From ab3b4523567fef50e6ef183d002e8191379a0927 Mon Sep 17 00:00:00 2001 From: Masahiro Nakagawa Date: Fri, 15 Mar 2019 09:15:17 +0900 Subject: [PATCH 1/2] parser_regexp: Check named capture. ref #2330 Signed-off-by: Masahiro Nakagawa --- lib/fluent/plugin/parser_regexp.rb | 4 ++++ test/plugin/test_parser_regexp.rb | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/fluent/plugin/parser_regexp.rb b/lib/fluent/plugin/parser_regexp.rb index c0636ebf34..79ad558269 100644 --- a/lib/fluent/plugin/parser_regexp.rb +++ b/lib/fluent/plugin/parser_regexp.rb @@ -40,6 +40,10 @@ def configure(conf) @expression = Regexp.compile(@expression.source, options) end @regexp = @expression # For backward compatibility + + if @expression.named_captures.empty? + raise Fluent::ConfigError, "No named captures in 'expression' parameter. The regexp must have at least one named capture" + end end def parse(text) diff --git a/test/plugin/test_parser_regexp.rb b/test/plugin/test_parser_regexp.rb index b8ed02125c..7fc5a98604 100644 --- a/test/plugin/test_parser_regexp.rb +++ b/test/plugin/test_parser_regexp.rb @@ -153,6 +153,15 @@ def create_driver(conf) end sub_test_case "configure" do + def test_bad_expression + conf = { + 'expression' => %q!/.*/!, + } + assert_raise Fluent::ConfigError do + create_driver(conf) + end + end + def test_default_options conf = { 'expression' => %q!/^(?[^ ]*) [^ ]* (?[^ ]*) \[(?