Skip to content

Commit

Permalink
fix empty rules map that should return an empty json object instead o…
Browse files Browse the repository at this point in the history
…f false (#23)
  • Loading branch information
fifthaxe authored and diegoholiveira committed Nov 21, 2019
1 parent 548f9d9 commit dc98137
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions internal/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ func GetScenariosFromOfficialTestSuite() Tests {
return tests
}

// add missing but relevant scenarios
var rule []interface{}

scenarios = append(scenarios,
append(rule,
make(map[string]interface {}, 0),
make(map[string]interface {}, 0),
make(map[string]interface {}, 0)))

for _, scenario := range scenarios {
if reflect.ValueOf(scenario).Kind() == reflect.String {
continue
Expand Down
3 changes: 2 additions & 1 deletion jsonlogic.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ func apply(rules, data interface{}) interface{} {
return operation(operator, parseValues(values, data), data)
}

return false
// an empty-map rule should return an empty-map
return make(map[string]interface{})
}

// Apply read the rule and it's data from io.Reader, executes it
Expand Down

0 comments on commit dc98137

Please sign in to comment.