From dc98137f095e8bbf0d028ef6520f409e8ed13046 Mon Sep 17 00:00:00 2001 From: fifthaxe <25035563+fifthaxe@users.noreply.github.com> Date: Thu, 21 Nov 2019 16:55:52 +0100 Subject: [PATCH] fix empty rules map that should return an empty json object instead of false (#23) --- 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