Skip to content

Commit

Permalink
Merge pull request #3 from zhouzhuojie/zz/fix-null-json-value
Browse files Browse the repository at this point in the history
Fix null json value
  • Loading branch information
zhouzhuojie authored May 1, 2018
2 parents c70410a + 461ba1d commit 34882af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ func evaluateSubtree(expr Expr, args map[string]interface{}) (Expr, error) {
return falseExpr, fmt.Errorf("argument: %v not found", index)
}

kind := reflect.TypeOf(args[index]).Kind()
typeof := reflect.TypeOf(args[index])
if typeof == nil {
return falseExpr, fmt.Errorf("Unsupported argument nil type")
}
kind := typeof.Kind()
switch kind {
case reflect.Int:
return &NumberLiteral{Val: float64(args[index].(int))}, nil
Expand Down
2 changes: 2 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ func TestJSON(t *testing.T) {
{`{foo} contains 123`, `{"foo": ["123"]}`, false, true},
{`{foo} not contains 123`, `{"foo": [124]}`, true, false},
{`{foo} not contains "123"`, `{"foo": ["124"]}`, true, false},
{`{foo} not contains "123"`, `{"foo": null}`, false, true},
{`{foo} not contains "123"`, `{}`, false, true},
}

for _, test := range tests {
Expand Down

0 comments on commit 34882af

Please sign in to comment.