summaryrefslogtreecommitdiffstats
path: root/app/models/setting.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-03-15 14:38:46 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-03-15 14:38:46 +0000
commited2a3a2244980bc39fba05a0d0e4de2e0b628211 (patch)
tree124a912bd5ada269344feb5f542b926ca6528326 /app/models/setting.rb
parent5c43b4860e752965329e38a11a7e3f4b266b2d5b (diff)
downloadredmine-ed2a3a2244980bc39fba05a0d0e4de2e0b628211.tar.gz
redmine-ed2a3a2244980bc39fba05a0d0e4de2e0b628211.zip
Make sure that settings are unserialized as UTF-8 encoded strings (#19305).
git-svn-id: http://svn.redmine.org/redmine/trunk@14112 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/setting.rb')
-rw-r--r--app/models/setting.rb24
1 files changed, 23 insertions, 1 deletions
diff --git a/app/models/setting.rb b/app/models/setting.rb
index ca280ebcd..2574649f3 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -91,7 +91,10 @@ class Setting < ActiveRecord::Base
def value
v = read_attribute(:value)
# Unserialize serialized settings
- v = YAML::load(v) if available_settings[name]['serialized'] && v.is_a?(String)
+ if available_settings[name]['serialized'] && v.is_a?(String)
+ v = YAML::load(v)
+ v = force_utf8_strings(v)
+ end
v = v.to_sym if available_settings[name]['format'] == 'symbol' && !v.blank?
v
end
@@ -238,6 +241,25 @@ END_SRC
load_plugin_settings
private
+
+ def force_utf8_strings(arg)
+ if arg.is_a?(String)
+ arg.dup.force_encoding('UTF-8')
+ elsif arg.is_a?(Array)
+ arg.map do |a|
+ force_utf8_strings(a)
+ end
+ elsif arg.is_a?(Hash)
+ arg = arg.dup
+ arg.each do |k,v|
+ arg[k] = force_utf8_strings(v)
+ end
+ arg
+ else
+ arg
+ end
+ end
+
# Returns the Setting instance for the setting named name
# (record found in database or new record with default value)
def self.find_or_default(name)