From d890923f0e70c179dc2c4cff5e279957bf723f76 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 --- act/exprparser/functions.go | 2 +- act/exprparser/functions_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/act/exprparser/functions.go b/act/exprparser/functions.go index 64103e07..37a38db5 100644 --- a/act/exprparser/functions.go +++ b/act/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/act/exprparser/functions_test.go b/act/exprparser/functions_test.go index bdae533e..3c3d3477 100644 --- a/act/exprparser/functions_test.go +++ b/act/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{