From ae98055f3387cba23c71d13e37498ccaee1bb787 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Mon, 12 Mar 2018 12:26:56 +0900 Subject: [PATCH 1/2] Support pattern start with character classes In prevous version, following pattern raises syntax error: @type grep key price pattern [1-9]\d* This example is derrived from https://docs.fluentd.org/v1.0/articles/filter_grep#-directive --- lib/fluent/plugin/filter_grep.rb | 12 ++++++++++-- test/plugin/test_filter_grep.rb | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) 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..5f97d38470 100644 --- a/test/plugin/test_filter_grep.rb +++ b/test/plugin/test_filter_grep.rb @@ -73,6 +73,20 @@ def create_driver(conf = '') end end end + + sub_test_case "pattern with slashes" do + test "start with character classes" do + conf = %[ + regexp1 message test + + 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 From bdf4de288e82f9e84cb88aec554d1b151005ddd3 Mon Sep 17 00:00:00 2001 From: Kenji Okimoto Date: Tue, 13 Mar 2018 09:28:09 +0900 Subject: [PATCH 2/2] Remove garbage line --- test/plugin/test_filter_grep.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/plugin/test_filter_grep.rb b/test/plugin/test_filter_grep.rb index 5f97d38470..18a40cd198 100644 --- a/test/plugin/test_filter_grep.rb +++ b/test/plugin/test_filter_grep.rb @@ -77,7 +77,6 @@ def create_driver(conf = '') sub_test_case "pattern with slashes" do test "start with character classes" do conf = %[ - regexp1 message test key message pattern /[a-z]test/