From fa44901c57fe7f4962dc19ce5b5588e8ec606ac2 Mon Sep 17 00:00:00 2001 From: fifthaxe <25035563+fifthaxe@users.noreply.github.com> Date: Fri, 29 May 2020 15:13:38 +0200 Subject: [PATCH] Fix #32 (#33) * fix empty rules map that should return an empty json object instead of false * fix invalid comparisons to nil value #32 Co-authored-by: Ken Polizzi --- comp.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/comp.go b/comp.go index 8c447a8..56098b3 100644 --- a/comp.go +++ b/comp.go @@ -9,6 +9,11 @@ func less(a, b interface{}) bool { return toNumber(b) > toNumber(a) } + // comparison to a nil value is falsy + if a == nil || b == nil { + return false + } + return toString(b) > toString(a) } @@ -27,8 +32,15 @@ func equals(a, b interface{}) bool { if isNumber(a) { return toNumber(a) == toNumber(b) } + + // comparison to a nil value is falsy + if a == nil || b == nil { + return false + } + if isBool(a) { return isTrue(a) == isTrue(b) } + return toString(a) == toString(b) }