diff --git a/jsonlogic.go b/jsonlogic.go index 704cbf5..6968101 100644 --- a/jsonlogic.go +++ b/jsonlogic.go @@ -423,8 +423,8 @@ func some(values, data interface{}) interface{} { for _, value := range subject.([]interface{}) { v := apply( solveVars( - solveVars(parsed[1], value), - data, + solveVars(parsed[1], data), + value, ), value, ) diff --git a/jsonlogic_test.go b/jsonlogic_test.go index feefb9c..5bda383 100644 --- a/jsonlogic_test.go +++ b/jsonlogic_test.go @@ -907,3 +907,28 @@ func TestIssue79(t *testing.T) { expected := `true` assert.JSONEq(t, expected, result.String()) } + +func TestIssue81(t *testing.T) { + rule := `{ + "some": [ + {"var": "A"}, + {"!=": [ + {"var": ".B"}, + {"var": "B"} + ]} + ]} + ` + + data := `{"A":[{"B":1}], "B":2}` + + var result bytes.Buffer + + err := Apply(strings.NewReader(rule), strings.NewReader(data), &result) + + if err != nil { + t.Fatal(err) + } + + expected := `true` + assert.JSONEq(t, expected, result.String()) +} diff --git a/vars.go b/vars.go index b375eb9..10bf073 100644 --- a/vars.go +++ b/vars.go @@ -45,7 +45,14 @@ func solveVars(values, data interface{}) interface{} { } func getVar(value, data interface{}) interface{} { - if value == nil || (isString(value) && toString(value) == "") { + if value == nil { + if !isPrimitive(data) { + return nil + } + return data + } + + if isString(value) && toString(value) == "" { return data }