Skip to content

Commit

Permalink
fqdn/matchpattern: reuse regexp char escape
Browse files Browse the repository at this point in the history
Reuse escapeRegexpCharacters func that implement the same escaping to
avoid duplication.

Signed-off-by: Odin Ugedal <ougedal@palantir.com>
  • Loading branch information
odinuge authored and aanm committed Jan 27, 2023
1 parent e15524b commit 562ef20
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions pkg/fqdn/matchpattern/matchpattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ func ToAnchoredRegexp(pattern string) string {
return "(^(" + allowedDNSCharsREGroup + "+[.])+$)|(^[.]$)"
}

// base case. * becomes .*, but only for DNS valid characters
// NOTE: this only works because the case above does not leave the *
pattern = strings.Replace(pattern, "*", allowedDNSCharsREGroup+"*", -1)

// base case. "." becomes a literal .
pattern = strings.Replace(pattern, ".", "[.]", -1)
pattern = escapeRegexpCharacters(pattern)

// Anchor the match to require the whole string to match this expression
return "^" + pattern + "$"
Expand Down

0 comments on commit 562ef20

Please sign in to comment.