From 655a5c8e47314086e589b3e67c7b167c68df96b6 Mon Sep 17 00:00:00 2001 From: Vladimir Vagaytsev Date: Wed, 12 Jul 2023 13:42:38 +0200 Subject: [PATCH] fix(template): allow `null` as a valid argument in helper functions --- core/src/template-string/functions.ts | 6 ++++-- core/test/unit/src/template-string.ts | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core/src/template-string/functions.ts b/core/src/template-string/functions.ts index 7738c0c24e..4b4241c4b0 100644 --- a/core/src/template-string/functions.ts +++ b/core/src/template-string/functions.ts @@ -479,11 +479,13 @@ export function callHelperFunction({ const resolvedArgs: any[] = [] for (const arg of args) { - if (arg._error) { + // arg can be null here because some helpers allow nulls as valid args + if (arg && arg._error) { return arg } - if (arg && arg.resolved) { + // allow nulls as valid arg values + if (arg && arg.resolved !== undefined) { resolvedArgs.push(arg.resolved) } else { resolvedArgs.push(arg) diff --git a/core/test/unit/src/template-string.ts b/core/test/unit/src/template-string.ts index bfb0c55e4b..57b56b31fa 100644 --- a/core/test/unit/src/template-string.ts +++ b/core/test/unit/src/template-string.ts @@ -1107,6 +1107,20 @@ describe("resolveTemplateString", () => { }) }) + context("isEmpty", () => { + context("allows nulls", () => { + it("resolves null as 'true'", () => { + const res = resolveTemplateString("${isEmpty(null)}", new TestContext({})) + expect(res).to.be.true + }) + + it("resolves references to null as 'true'", () => { + const res = resolveTemplateString("${isEmpty(a)}", new TestContext({ a: null })) + expect(res).to.be.true + }) + }) + }) + context("slice", () => { it("allows numeric indices", () => { const res = resolveTemplateString("${slice(foo, 0, 3)}", new TestContext({ foo: "abcdef" }))