mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-23 00:41:14 +00:00
Make sure that strings of serialized settings are UTF-8 encoded (#19305).
git-svn-id: http://svn.redmine.org/redmine/trunk@14067 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
f2d9af6dc3
commit
a5b18b631c
@ -91,7 +91,10 @@ class Setting < ActiveRecord::Base
|
|||||||
def value
|
def value
|
||||||
v = read_attribute(:value)
|
v = read_attribute(:value)
|
||||||
# Unserialize serialized settings
|
# 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)
|
||||||
|
force_utf8_strings(v)
|
||||||
|
end
|
||||||
v = v.to_sym if available_settings[name]['format'] == 'symbol' && !v.blank?
|
v = v.to_sym if available_settings[name]['format'] == 'symbol' && !v.blank?
|
||||||
v
|
v
|
||||||
end
|
end
|
||||||
@ -238,6 +241,23 @@ END_SRC
|
|||||||
load_plugin_settings
|
load_plugin_settings
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def force_utf8_strings(arg)
|
||||||
|
if arg.is_a?(String)
|
||||||
|
arg.force_encoding('UTF-8')
|
||||||
|
elsif arg.is_a?(Array)
|
||||||
|
arg.each do |a|
|
||||||
|
force_utf8_strings(a)
|
||||||
|
end
|
||||||
|
elsif arg.is_a?(Hash)
|
||||||
|
arg.each do |k,v|
|
||||||
|
force_utf8_strings(k)
|
||||||
|
force_utf8_strings(v)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
arg
|
||||||
|
end
|
||||||
|
|
||||||
# Returns the Setting instance for the setting named name
|
# Returns the Setting instance for the setting named name
|
||||||
# (record found in database or new record with default value)
|
# (record found in database or new record with default value)
|
||||||
def self.find_or_default(name)
|
def self.find_or_default(name)
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
# encoding: utf-8
|
||||||
|
#
|
||||||
# Redmine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2015 Jean-Philippe Lang
|
# Copyright (C) 2006-2015 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
@ -101,4 +103,18 @@ class SettingTest < ActiveSupport::TestCase
|
|||||||
assert_equal [10, 25, 50], Setting.per_page_options_array
|
assert_equal [10, 25, 50], Setting.per_page_options_array
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_serialized_setting_should_be_loaded_as_utf8_encoded_strings
|
||||||
|
scm = 'исправлено'
|
||||||
|
scm.force_encoding('BINARY')
|
||||||
|
Setting.enabled_scm = [scm]
|
||||||
|
Setting.clear_cache
|
||||||
|
|
||||||
|
s = Setting.enabled_scm
|
||||||
|
assert_equal ['исправлено'], s
|
||||||
|
assert_equal 'UTF-8', s.first.encoding.name
|
||||||
|
ensure
|
||||||
|
Setting.where(:name => 'enabled_scm').delete_all
|
||||||
|
Setting.clear_cache
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user