Skip to content

Commit

Permalink
Fix bug with equals/not-equals for empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
zix99 committed Apr 1, 2023
1 parent 2883a9b commit 2cdaf89
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/expressions/stdlib/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ var StandardFunctions = map[string]KeyBuilderFunction{
"unless": KeyBuilderFunction(kfUnless),
"eq": stringComparator(func(a, b string) string {
if a == b {
return a
return TruthyVal
}
return ""
return FalsyVal
}),
"neq": stringComparator(func(a, b string) string {
if a != b {
return a
return TruthyVal
}
return ""
return FalsyVal
}),
"not": KeyBuilderFunction(kfNot),
"lt": arithmaticEqualityHelper(func(a, b float64) bool { return a < b }),
Expand Down
4 changes: 4 additions & 0 deletions pkg/expressions/stdlib/funcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func TestIfStatement(t *testing.T) {
`{if {0} {1} efg} {if {0} abc} {if {not {0}} a b} {if "" a} {if "" a b}`,
"q abc b b")
testExpression(t, mockContext("abc efg"), `{if {eq {0} "abc efg"} beq}`, "beq")
testExpression(t, mockContext(), `{if {eq "" ""} true false}`, "true")
testExpression(t, mockContext(), `{if {eq "" "abc"} true false}`, "false")
testExpression(t, mockContext(), `{if {neq "" "abc"} true false}`, "true")
testExpression(t, mockContext(), `{if {neq "" ""} true false}`, "false")
}

func TestUnlessStatement(t *testing.T) {
Expand Down

0 comments on commit 2cdaf89

Please sign in to comment.