From 3149488dd4ad851c3f30f0c97f28429dbe377bee Mon Sep 17 00:00:00 2001 From: Masahiro Nakagawa Date: Tue, 30 Jan 2018 22:05:59 +0900 Subject: [PATCH] Fix config_param for string type with frozen string. fix #1827 --- lib/fluent/config/types.rb | 6 +++++- test/config/test_configurable.rb | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/fluent/config/types.rb b/lib/fluent/config/types.rb index 4f5df084a4..f41d451b6a 100644 --- a/lib/fluent/config/types.rb +++ b/lib/fluent/config/types.rb @@ -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] diff --git a/test/config/test_configurable.rb b/test/config/test_configurable.rb index 66d34b0847..2550065497 100644 --- a/test/config/test_configurable.rb +++ b/test/config/test_configurable.rb @@ -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("", "", {})) }