From fab428c0585eda76af78b32cbb485a17c1c457ad Mon Sep 17 00:00:00 2001 From: Ken Polizzi Date: Wed, 20 Nov 2019 11:39:21 +0000 Subject: [PATCH] fix empty rules map that should return an empty json object instead of false --- internal/testing.go | 9 +++++++++ jsonlogic.go | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/testing.go b/internal/testing.go index 9d0b1f1..54ccfaf 100644 --- a/internal/testing.go +++ b/internal/testing.go @@ -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 diff --git a/jsonlogic.go b/jsonlogic.go index 8a07230..86d6382 100644 --- a/jsonlogic.go +++ b/jsonlogic.go @@ -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