Skip to content

Commit

Permalink
Ensure all boolean output from map is considered (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Henrique Oliveira authored Apr 28, 2024
1 parent 967fd4b commit 46da249
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion arrays.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func _map(values, data interface{}) interface{} {
for _, value := range subject.([]interface{}) {
v := parseValues(logic, value)

if isTrue(v) || isNumber(v) {
if isTrue(v) || isNumber(v) || isBool(v) {
result = append(result, v)
}
}
Expand Down
37 changes: 37 additions & 0 deletions internal/issues/0083_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package issues_test

import (
"bytes"
"strings"
"testing"

"github.com/stretchr/testify/assert"

"github.com/diegoholiveira/jsonlogic/v3"
)

func TestIssue83(t *testing.T) {
rule := `{
"map": [
{"var": "listOfLists"},
{"in": ["item_a", {"var": ""}]}
]
}`

data := `{
"listOfLists": [
["item_a", "item_b", "item_c"],
["item_b", "item_c"],
["item_a", "item_c"]
]
}`

var result bytes.Buffer

err := jsonlogic.Apply(strings.NewReader(rule), strings.NewReader(data), &result)

if assert.Nil(t, err) {
expected := `[true,false,true]`
assert.JSONEq(t, expected, result.String())
}
}

0 comments on commit 46da249

Please sign in to comment.