Skip to content

Commit

Permalink
Merge pull request #1887 from okkez/support-pattern-start-with-charac…
Browse files Browse the repository at this point in the history
…ter-classes

Support pattern start with character classes
  • Loading branch information
repeatedly authored Mar 15, 2018
2 parents 284a65e + bdf4de2 commit b999f80
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
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

0 comments on commit b999f80

Please sign in to comment.