From e7fd2002379c9d8a5014db1fc3f8dab514a3d67f Mon Sep 17 00:00:00 2001 From: Lorenz Bausch Date: Sat, 7 May 2022 20:51:52 +0200 Subject: [PATCH] Keep original pattern for later use --- internal/filter/filter.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/filter/filter.go b/internal/filter/filter.go index 3e16c9316..ddfa3ebaf 100644 --- a/internal/filter/filter.go +++ b/internal/filter/filter.go @@ -18,6 +18,7 @@ type patternPart struct { // Pattern represents a preparsed filter pattern type Pattern struct { + original string parts []patternPart isNegated bool } @@ -31,6 +32,9 @@ func prepareStr(str string) ([]string, error) { func preparePattern(patternStr string) Pattern { var negate bool + + originalPattern := patternStr + if patternStr[0] == '!' { negate = true patternStr = patternStr[1:] @@ -48,7 +52,7 @@ func preparePattern(patternStr string) Pattern { parts[i] = patternPart{part, isSimple} } - return Pattern{parts, negate} + return Pattern{originalPattern, parts, negate} } // Split p into path components. Assuming p has been Cleaned, no component @@ -130,7 +134,7 @@ func childMatch(pattern Pattern, strs []string) (matched bool, err error) { } else { l = len(strs) } - return match(Pattern{pattern.parts[0:l], pattern.isNegated}, strs) + return match(Pattern{pattern.original, pattern.parts[0:l], pattern.isNegated}, strs) } func hasDoubleWildcard(list Pattern) (ok bool, pos int) { @@ -158,7 +162,7 @@ func match(pattern Pattern, strs []string) (matched bool, err error) { } newPat = append(newPat, pattern.parts[pos+1:]...) - matched, err := match(Pattern{newPat, pattern.isNegated}, strs) + matched, err := match(Pattern{pattern.original, newPat, pattern.isNegated}, strs) if err != nil { return false, err }