diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-11-19 19:53:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-19 19:53:14 +0100 |
commit | 2755d0255c94ac2ef797636935f83e3351d4d5af (patch) | |
tree | 46c7c7f032fcb92797a873f713a805225da841ea | |
parent | 671e5ee42d4eb71fc0238e8b0b1e4a68b1def156 (diff) | |
parent | 6011149cae81a43e0d9c8fefc7413a61ae4f7eac (diff) | |
download | podman-2755d0255c94ac2ef797636935f83e3351d4d5af.tar.gz podman-2755d0255c94ac2ef797636935f83e3351d4d5af.tar.bz2 podman-2755d0255c94ac2ef797636935f83e3351d4d5af.zip |
Merge pull request #12364 from flouthoc/fix-filter-pattern
filter: use `filepath.Match` to maintain consistency with other pattern matching in podman
-rw-r--r-- | pkg/util/filters.go | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/pkg/util/filters.go b/pkg/util/filters.go index 5af868873..99fac2478 100644 --- a/pkg/util/filters.go +++ b/pkg/util/filters.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" "net/http" - "regexp" + "path/filepath" "strings" "time" @@ -95,24 +95,13 @@ func PrepareFilters(r *http.Request) (*map[string][]string, error) { return &filterMap, nil } -func wildCardToRegexp(pattern string) string { - var result strings.Builder - for i, literal := range strings.Split(pattern, "*") { - // Replace * with .* - if i > 0 { - result.WriteString(".*") - } - // Quote any regular expression meta characters in the - // literal text. - result.WriteString(regexp.QuoteMeta(literal)) - } - return result.String() -} - func matchPattern(pattern string, value string) bool { if strings.Contains(pattern, "*") { - result, _ := regexp.MatchString(wildCardToRegexp(pattern), value) - return result + filter := fmt.Sprintf("*%s*", pattern) + filter = strings.ReplaceAll(filter, string(filepath.Separator), "|") + newName := strings.ReplaceAll(value, string(filepath.Separator), "|") + match, _ := filepath.Match(filter, newName) + return match } return false } |