diff --git a/lib/fluent/plugin/filter_grep.rb b/lib/fluent/plugin/filter_grep.rb index d289de70f2..87a5d378e6 100644 --- a/lib/fluent/plugin/filter_grep.rb +++ b/lib/fluent/plugin/filter_grep.rb @@ -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 @@ -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 diff --git a/test/plugin/test_filter_grep.rb b/test/plugin/test_filter_grep.rb index 2eb6dba178..18a40cd198 100644 --- a/test/plugin/test_filter_grep.rb +++ b/test/plugin/test_filter_grep.rb @@ -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 = %[ + + key message + pattern /[a-z]test/ + + ] + d = create_driver(conf) + assert_equal(/[a-z]test/, d.instance.regexps.first.pattern) + end + end end sub_test_case 'filter_stream' do