From 2719f7e97e34f1417b0044a4e517d31001cd22f7 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 2 Nov 2021 16:30:43 +0000 Subject: [PATCH] Fixing bug #3195 with zero/falsy values not being passed out of bindings. --- packages/string-templates/src/helpers/index.js | 2 +- packages/string-templates/test/basic.spec.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/string-templates/src/helpers/index.js b/packages/string-templates/src/helpers/index.js index 201ecb83da..b43fef44dc 100644 --- a/packages/string-templates/src/helpers/index.js +++ b/packages/string-templates/src/helpers/index.js @@ -31,7 +31,7 @@ const HELPERS = [ } // null/undefined values produce bad results if (value == null || typeof value !== "string") { - return value || "" + return value == null ? "" : value } if (value && value.string) { value = value.string diff --git a/packages/string-templates/test/basic.spec.js b/packages/string-templates/test/basic.spec.js index 2e63ce8a5f..b437e386fc 100644 --- a/packages/string-templates/test/basic.spec.js +++ b/packages/string-templates/test/basic.spec.js @@ -125,6 +125,18 @@ describe("check the utility functions", () => { }) }) +describe("check falsy values", () => { + it("should get a zero out when context contains it", async () => { + const output = await processString("{{ number }}", { number: 0 }) + expect(output).toEqual("0") + }) + + it("should get false out when context contains it", async () => { + const output = await processString("{{ bool }}", { bool: false }) + expect(output).toEqual("false") + }) +}) + describe("check manifest", () => { it("should be able to retrieve the manifest", () => { const manifest = getManifest()