Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check right slash position #2176

Merged
merged 2 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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