Skip to content

Commit

Permalink
Merge pull request #1838 from fluent/fix-fronze-string-with-config_param
Browse files Browse the repository at this point in the history
Fix config_param for string type with frozen string. fix #1827
  • Loading branch information
repeatedly authored Jan 31, 2018
2 parents 19c4eb7 + 3149488 commit f833b2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/fluent/config/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ def self.bool_value(str)
end
end

STRING_TYPE = Proc.new { |val, opts| val.to_s.force_encoding(Encoding::UTF_8) }
STRING_TYPE = Proc.new { |val, opts|
v = val.to_s
v = v.frozen? ? v.dup : v # config_param can't assume incoming string is mutable
v.force_encoding(Encoding::UTF_8)
}
ENUM_TYPE = Proc.new { |val, opts|
s = val.to_sym
list = opts[:list]
Expand Down
5 changes: 5 additions & 0 deletions test/config/test_configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,11 @@ class TestConfigurable < ::Test::Unit::TestCase
assert_instance_of(ConfigurableSpec::Base2, b2.configure(config_element("", "", {"name1" => "t1", "name5" => "t5", "opt3" => "a"})))
end

test 'can accept frozen string' do
b2 = ConfigurableSpec::Base2.new
assert_instance_of(ConfigurableSpec::Base2, b2.configure(config_element("", "", {"name1" => "t1".freeze, "name5" => "t5", "opt3" => "a"})))
end

test 'raise errors without any specifications for param without defaults' do
b2 = ConfigurableSpec::Base2.new
assert_raise(Fluent::ConfigError) { b2.configure(config_element("", "", {})) }
Expand Down

0 comments on commit f833b2f

Please sign in to comment.