Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix empty rules object that should return an empty object instead of false #23

Merged
merged 1 commit into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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