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

Support pattern start with character classes #1887

Merged
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
12 changes: 10 additions & 2 deletions lib/fluent/plugin/filter_grep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def initialize
config_param :key, :string
desc "The regular expression."
config_param :pattern do |value|
Regexp.compile(value)
if value.start_with?("/") and value.end_with?("/")
Regexp.compile(value[1..-2])
else
Regexp.compile(value)
end
end
end

Expand All @@ -50,7 +54,11 @@ def initialize
config_param :key, :string
desc "The regular expression."
config_param :pattern do |value|
Regexp.compile(value)
if value.start_with?("/") and value.end_with("/")
Regexp.compile(value[1..-2])
else
Regexp.compile(value)
end
end
end

Expand Down
13 changes: 13 additions & 0 deletions test/plugin/test_filter_grep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ def create_driver(conf = '')
end
end
end

sub_test_case "pattern with slashes" do
test "start with character classes" do
conf = %[
<regexp>
key message
pattern /[a-z]test/
</regexp>
]
d = create_driver(conf)
assert_equal(/[a-z]test/, d.instance.regexps.first.pattern)
end
end
end

sub_test_case 'filter_stream' do
Expand Down