Skip to content

Commit

Permalink
fix wildcard match
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBugwadia committed Nov 29, 2020
1 parent 27f9516 commit 251129d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/engine/variables/operator/equal.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (eh EqualHandler) validateValueWithMapPattern(key map[string]interface{}, v

func (eh EqualHandler) validateValueWithStringPattern(key string, value interface{}) bool {
if val, ok := value.(string); ok {
return wildcard.Match(key, val)
return wildcard.Match(val, key)
}

eh.log.Info("Expected type string", "value", value, "type", fmt.Sprintf("%T", value))
Expand Down
5 changes: 3 additions & 2 deletions pkg/engine/variables/operator/in.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package operator
import (
"encoding/json"
"fmt"

"github.com/minio/minio/pkg/wildcard"

"github.com/go-logr/logr"
Expand Down Expand Up @@ -76,14 +77,14 @@ func keyExistsInArray(key string, value interface{}, log logr.Logger) (invalidTy

case string:

if wildcard.Match(key, valuesAvailable) {
if wildcard.Match(valuesAvailable, key) {
keyExists = true
return
}

var arr []string
if err := json.Unmarshal([]byte(valuesAvailable), &arr); err != nil {
log.Error(err, "failed to unmarshal to string slice", "value", value)
log.Error(err, "failed to unmarshal value to JSON string array", "key", key, "value", value)
invalidType = true
return
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/engine/variables/operator/notequal.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ func (neh NotEqualHandler) validateValueWithMapPattern(key map[string]interface{

func (neh NotEqualHandler) validateValueWithStringPattern(key string, value interface{}) bool {
if val, ok := value.(string); ok {
return !wildcard.Match(key, val)
return !wildcard.Match(val, key)
}

neh.log.Info("Expected type string", "value", value, "type", fmt.Sprintf("%T", value))
return false
}
Expand Down

0 comments on commit 251129d

Please sign in to comment.