@@ -91,7 +91,10 class Setting < ActiveRecord::Base | |||
|
91 | 91 | def value |
|
92 | 92 | v = read_attribute(:value) |
|
93 | 93 | # Unserialize serialized settings |
|
94 |
|
|
|
94 | if available_settings[name]['serialized'] && v.is_a?(String) | |
|
95 | v = YAML::load(v) | |
|
96 | v = force_utf8_strings(v) | |
|
97 | end | |
|
95 | 98 | v = v.to_sym if available_settings[name]['format'] == 'symbol' && !v.blank? |
|
96 | 99 | v |
|
97 | 100 | end |
@@ -238,6 +241,25 END_SRC | |||
|
238 | 241 | load_plugin_settings |
|
239 | 242 | |
|
240 | 243 | private |
|
244 | ||
|
245 | def force_utf8_strings(arg) | |
|
246 | if arg.is_a?(String) | |
|
247 | arg.dup.force_encoding('UTF-8') | |
|
248 | elsif arg.is_a?(Array) | |
|
249 | arg.map do |a| | |
|
250 | force_utf8_strings(a) | |
|
251 | end | |
|
252 | elsif arg.is_a?(Hash) | |
|
253 | arg = arg.dup | |
|
254 | arg.each do |k,v| | |
|
255 | arg[k] = force_utf8_strings(v) | |
|
256 | end | |
|
257 | arg | |
|
258 | else | |
|
259 | arg | |
|
260 | end | |
|
261 | end | |
|
262 | ||
|
241 | 263 | # Returns the Setting instance for the setting named name |
|
242 | 264 | # (record found in database or new record with default value) |
|
243 | 265 | def self.find_or_default(name) |
@@ -1,3 +1,5 | |||
|
1 | # encoding: utf-8 | |
|
2 | # | |
|
1 | 3 | # Redmine - project management software |
|
2 | 4 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
3 | 5 | # |
@@ -101,4 +103,25 class SettingTest < ActiveSupport::TestCase | |||
|
101 | 103 | assert_equal [10, 25, 50], Setting.per_page_options_array |
|
102 | 104 | end |
|
103 | 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 | 127 | end |
General Comments 0
You need to be logged in to leave comments.
Login now