##// END OF EJS Templates
Merged r14112 (#19305)....
Jean-Philippe Lang -
r13732:2bfeaf886e7d
parent child
Show More
@@ -94,7 +94,10 class Setting < ActiveRecord::Base
94 def value
94 def value
95 v = read_attribute(:value)
95 v = read_attribute(:value)
96 # Unserialize serialized settings
96 # Unserialize serialized settings
97 v = YAML::load(v) if @@available_settings[name]['serialized'] && v.is_a?(String)
97 if @@available_settings[name]['serialized'] && v.is_a?(String)
98 v = YAML::load(v)
99 v = force_utf8_strings(v)
100 end
98 v = v.to_sym if @@available_settings[name]['format'] == 'symbol' && !v.blank?
101 v = v.to_sym if @@available_settings[name]['format'] == 'symbol' && !v.blank?
99 v
102 v
100 end
103 end
@@ -237,6 +240,25 END_SRC
237 end
240 end
238
241
239 private
242 private
243
244 def force_utf8_strings(arg)
245 if arg.is_a?(String)
246 arg.dup.force_encoding('UTF-8')
247 elsif arg.is_a?(Array)
248 arg.map do |a|
249 force_utf8_strings(a)
250 end
251 elsif arg.is_a?(Hash)
252 arg = arg.dup
253 arg.each do |k,v|
254 arg[k] = force_utf8_strings(v)
255 end
256 arg
257 else
258 arg
259 end
260 end
261
240 # Returns the Setting instance for the setting named name
262 # Returns the Setting instance for the setting named name
241 # (record found in database or new record with default value)
263 # (record found in database or new record with default value)
242 def self.find_or_default(name)
264 def self.find_or_default(name)
@@ -1,3 +1,5
1 # encoding: utf-8
2 #
1 # Redmine - project management software
3 # Redmine - project management software
2 # Copyright (C) 2006-2015 Jean-Philippe Lang
4 # Copyright (C) 2006-2015 Jean-Philippe Lang
3 #
5 #
@@ -101,4 +103,25 class SettingTest < ActiveSupport::TestCase
101 assert_equal [10, 25, 50], Setting.per_page_options_array
103 assert_equal [10, 25, 50], Setting.per_page_options_array
102 end
104 end
103 end
105 end
106
107 def test_setting_serialied_as_binary_should_be_loaded_as_utf8_encoded_strings
108 yaml = <<-YAML
109 ---
110 - keywords: !binary |
111 Zml4ZXMsY2xvc2VzLNC40YHQv9GA0LDQstC70LXQvdC+LNCz0L7RgtC+0LLQ
112 vizRgdC00LXQu9Cw0L3QvixmaXhlZA==
113
114 done_ratio: "100"
115 status_id: "5"
116 YAML
117
118 Setting.commit_update_keywords = {}
119 assert_equal 1, Setting.where(:name => 'commit_update_keywords').update_all(:value => yaml)
120 Setting.clear_cache
121
122 assert_equal 'UTF-8', Setting.commit_update_keywords.first['keywords'].encoding.name
123 ensure
124 Setting.where(:name => 'commit_update_keywords').delete_all
125 Setting.clear_cache
126 end
104 end
127 end
General Comments 0
You need to be logged in to leave comments. Login now