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

parser_regexp: Check named capture. ref #2330 #2331

Merged
merged 2 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions lib/fluent/plugin/parser_regexp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions test/plugin/test_parser_regexp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!/^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] \[(?<date>[^\]]*)\] "(?<flag>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)$/!,
Expand Down