Skip to content

Commit

Permalink
Escape { and }, do not fail on missing properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHX authored and ZauberNerd committed Dec 22, 2021
1 parent c9beb89 commit 686898e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/exprparser/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (impl *interperterImpl) getPropertyValue(left reflect.Value, property strin
}
}

return nil, fmt.Errorf("'%s' not found in '%s'", property, left.Type())
return nil, nil

case reflect.Slice:
var values []interface{}
Expand Down
8 changes: 6 additions & 2 deletions pkg/runner/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ func EvalBool(evaluator ExpressionEvaluator, expr string) (bool, error) {
return result, nil
}

func escapeFormatString(in string) string {
return strings.ReplaceAll(strings.ReplaceAll(in, "{", "{{"), "}", "}}")
}

//nolint:gocyclo
func rewriteSubExpression(in string, forceFormat bool) (string, error) {
if !strings.Contains(in, "${{") || !strings.Contains(in, "}}") {
Expand Down Expand Up @@ -237,11 +241,11 @@ func rewriteSubExpression(in string, forceFormat bool) (string, error) {
} else {
exprStart = strings.Index(in[pos:], "${{")
if exprStart != -1 {
formatOut += in[pos : pos+exprStart]
formatOut += escapeFormatString(in[pos : pos+exprStart])
exprStart = pos + exprStart + 3
pos = exprStart
} else {
formatOut += in[pos:]
formatOut += escapeFormatString(in[pos:])
pos = len(in)
}
}
Expand Down

0 comments on commit 686898e

Please sign in to comment.