Skip to content

Commit

Permalink
Merge pull request #2176 from okkez/check-rightslash-position
Browse files Browse the repository at this point in the history
Check right slash position
  • Loading branch information
repeatedly authored Nov 20, 2018
2 parents 23a9609 + 721e38d commit 604828f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/fluent/config/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions test/config/test_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 604828f

Please sign in to comment.