Skip to content

Commit

Permalink
Also parse bool value strictly on strict_config_value = true
Browse files Browse the repository at this point in the history
Should raise ConfigError on unrecognized strings or any other value
types to notify mistakes in user's config as early as possible.

Signed-off-by: Takuro Ashie <ashie@clear-code.com>
  • Loading branch information
ashie committed Nov 20, 2019
1 parent 0655c0b commit 7b2e9ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/fluent/config/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def self.bool_value(str, opts = {}, name = nil)
# parser should pass empty string in this case but changing behaviour may break existing environment so keep parser behaviour. Just ignore comment value in boolean handling for now.
if str.respond_to?('start_with?') && str.start_with?('#')
true
elsif opts[:strict]
raise Fluent::ConfigError, "#{name}: invalid bool value: #{str}"
else
nil
end
Expand Down
15 changes: 15 additions & 0 deletions test/config/test_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ class TestConfigTypes < ::Test::Unit::TestCase
test 'not assumed case' do |(expected, val)|
assert_equal(expected, Config.bool_value(val))
end

data("true" => [true, true],
"false" => [false, false],
"hoge" => [Fluent::ConfigError.new("name1: invalid bool value: hoge"), "hoge"],
"nill" => [nil, nil],
"integer" => [Fluent::ConfigError.new("name1: invalid bool value: 10"), 10])
test 'not assumed case with strict' do |(expected, val)|
if expected.kind_of? Exception
assert_raise(expected) do
Config.bool_value(val, { strict: true }, "name1")
end
else
assert_equal(expected, Config.bool_value(val, { strict: true }, "name1"))
end
end
end

sub_test_case 'Config.regexp_value' do
Expand Down

0 comments on commit 7b2e9ec

Please sign in to comment.