From 5083284deb804db5b9d5997ab4cf345b1c7ec069 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Tue, 22 Mar 2022 09:55:13 +0100 Subject: [PATCH] Fix: tojson(null) == 'null' (#1068) * Fix: tojson(null) == 'null' * Update test * Update functions_test.go --- pkg/exprparser/functions.go | 2 +- pkg/exprparser/functions_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/exprparser/functions.go b/pkg/exprparser/functions.go index 64103e0..37a38db 100644 --- a/pkg/exprparser/functions.go +++ b/pkg/exprparser/functions.go @@ -151,7 +151,7 @@ func (impl *interperterImpl) join(array reflect.Value, sep reflect.Value) (strin func (impl *interperterImpl) toJSON(value reflect.Value) (string, error) { if value.Kind() == reflect.Invalid { - return "", nil + return "null", nil } json, err := json.MarshalIndent(value.Interface(), "", " ") diff --git a/pkg/exprparser/functions_test.go b/pkg/exprparser/functions_test.go index bdae533..3c3d347 100644 --- a/pkg/exprparser/functions_test.go +++ b/pkg/exprparser/functions_test.go @@ -137,6 +137,7 @@ func TestFunctionToJSON(t *testing.T) { name string }{ {"toJSON(env) }}", "{\n \"key\": \"value\"\n}", "toJSON"}, + {"toJSON(null)", "null", "toJSON-null"}, } env := &EvaluationEnvironment{