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

MatchPattern: allow regex patterns #3071

Merged
merged 5 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/fluent/match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ def match(str)

class GlobMatchPattern < MatchPattern
def initialize(pat)
if pat.start_with?('/')
if pat.end_with?('/')
@regex = Regexp.new("\\A"+pat[1..-2]+"\\Z")
return
else
raise Fluent::ConfigError, "invalid match - regex"
end
end

stack = []
regex = ['']
escape = false
Expand Down
11 changes: 11 additions & 0 deletions test/test_match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ def test_multi_pattern_or
assert_or_not_match('a.b.** a.c', 'a.c.d')
end

def test_regex_pattern
assert_glob_match('/a/', 'a')
assert_glob_not_match('/a/', 'abc')
assert_glob_match('/a.*/', 'abc')
assert_glob_not_match('/b.*/', 'abc')
assert_glob_match('/a\..*/', 'a.b.c')
assert_glob_not_match('/(?!a\.).*/', 'a.b.c')
assert_glob_not_match('/a\..*/', 'b.b.c')
assert_glob_match('/(?!a\.).*/', 'b.b.c')
end

#def test_character_class
# assert_match('[a]', 'a')
# assert_match('[ab]', 'a')
Expand Down