Skip to content

Commit

Permalink
MatchPattern: allow regex patterns (#3071)
Browse files Browse the repository at this point in the history
* MatchPattern: allow regex patterns

Signed-off-by: Christian Ferbar <[email protected]>
Co-authored-by: Christian Ferbar <[email protected]>
  • Loading branch information
ferbar and Christian Ferbar authored Jul 21, 2020
1 parent be81226 commit b03ee59
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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

0 comments on commit b03ee59

Please sign in to comment.