Skip to content

Commit

Permalink
also trim in context query
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBugwadia committed Nov 25, 2020
1 parent 54f816c commit 75bd8e2
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/engine/context/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import (

//Query the JSON context with JMESPATH search path
func (ctx *Context) Query(query string) (interface{}, error) {
query = strings.TrimSpace(query)
if query == "" {
return nil, fmt.Errorf("invalid query (nil)")
}

var emptyResult interface{}
// check for white-listed variables
if !ctx.isWhiteListed(query) {
if !ctx.isBuiltInVariable(query) {
return emptyResult, fmt.Errorf("variable %s cannot be used", query)
}

Expand Down Expand Up @@ -40,7 +45,7 @@ func (ctx *Context) Query(query string) (interface{}, error) {
return result, nil
}

func (ctx *Context) isWhiteListed(variable string) bool {
func (ctx *Context) isBuiltInVariable(variable string) bool {
if len(ctx.builtInVars) == 0 {
return true
}
Expand Down

0 comments on commit 75bd8e2

Please sign in to comment.