Fix eval when types do not match between the lhs and rhs

Fixes #4306.
pull/6048/head
Jonathan A. Sternberg 2016-03-14 21:30:37 -04:00
parent d24f9a9fb5
commit f62f8a02dd
2 changed files with 7 additions and 5 deletions

View File

@ -3644,16 +3644,16 @@ func evalBinaryExpr(expr *BinaryExpr, m map[string]interface{}) interface{} {
// Evaluate if both sides are simple types.
switch lhs := lhs.(type) {
case bool:
rhs, _ := rhs.(bool)
rhs, ok := rhs.(bool)
switch expr.Op {
case AND:
return lhs && rhs
return ok && (lhs && rhs)
case OR:
return lhs || rhs
return ok && (lhs || rhs)
case EQ:
return lhs == rhs
return ok && (lhs == rhs)
case NEQ:
return lhs != rhs
return ok && (lhs != rhs)
}
case float64:
// Try the rhs as a float64 or int64

View File

@ -1013,10 +1013,12 @@ func TestEval(t *testing.T) {
// Boolean literals.
{in: `true AND false`, out: false},
{in: `true OR false`, out: true},
{in: `false = 4`, out: false},
// String literals.
{in: `'foo' = 'bar'`, out: false},
{in: `'foo' = 'foo'`, out: true},
{in: `'' = 4`, out: false},
// Regex literals.
{in: `'foo' =~ /f.*/`, out: true},