diff --git a/lib/fluent/config/types.rb b/lib/fluent/config/types.rb index aaff5d9141..958fc52c78 100644 --- a/lib/fluent/config/types.rb +++ b/lib/fluent/config/types.rb @@ -74,6 +74,9 @@ def self.regexp_value(str) return nil unless str return Regexp.compile(str) unless str.start_with?("/") right_slash_position = str.rindex("/") + if right_slash_position < str.size - 3 + raise Fluent::ConfigError, "invalid regexp: missing right slash: #{str}" + end options = str[(right_slash_position + 1)..-1] option = 0 option |= Regexp::IGNORECASE if options.include?("i") diff --git a/test/config/test_types.rb b/test/config/test_types.rb index a149b3b1a1..dd1bbace23 100644 --- a/test/config/test_types.rb +++ b/test/config/test_types.rb @@ -79,6 +79,14 @@ class TestConfigTypes < ::Test::Unit::TestCase test 'w/o slashes' do |(expected, str)| assert_equal(expected, Config.regexp_value(str)) end + + data("missing right slash" => "/regexp", + "too many options" => "/regexp/imx",) + test 'invalid regexp' do |(str)| + assert_raise(Fluent::ConfigError.new("invalid regexp: missing right slash: #{str}")) do + Config.regexp_value(str) + end + end end sub_test_case 'type converters for config_param definitions' do