From 7e4e0db30fc2dbe3805e289261678c83d72a5ec5 Mon Sep 17 00:00:00 2001 From: Michael Drury Date: Tue, 2 Feb 2021 20:28:27 +0000 Subject: [PATCH] Widening the allowance criteria for handlebars validity, check for any errors which suggest a simple type error from the context and allowing these through. --- packages/string-templates/src/index.js | 4 ++-- packages/string-templates/test/helpers.spec.js | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/string-templates/src/index.js b/packages/string-templates/src/index.js index 68652684a8..f3156c45d7 100644 --- a/packages/string-templates/src/index.js +++ b/packages/string-templates/src/index.js @@ -110,7 +110,7 @@ module.exports.makePropSafe = property => { * @returns {boolean} Whether or not the input string is valid. */ module.exports.isValid = string => { - const specialCases = ["isNumber", "expected a number"] + const specialCases = ["string", "number", "object", "array"] // don't really need a real context to check if its valid const context = {} try { @@ -118,7 +118,7 @@ module.exports.isValid = string => { return true } catch (err) { const msg = err ? err.message : "" - const foundCase = specialCases.find(spCase => msg.includes(spCase)) + const foundCase = specialCases.find(spCase => msg.toLowerCase().includes(spCase)) // special case for maths functions - don't have inputs yet return !!foundCase } diff --git a/packages/string-templates/test/helpers.spec.js b/packages/string-templates/test/helpers.spec.js index 7aaf6bf466..4a4ed6592a 100644 --- a/packages/string-templates/test/helpers.spec.js +++ b/packages/string-templates/test/helpers.spec.js @@ -311,4 +311,9 @@ describe("Cover a few complex use cases", () => { const output = await processString(`{{first ( split "a-b-c" "-") 2}}`, {}) expect(output).toBe(`a,b`) }) + + it("should confirm a subtraction validity", () => { + const validity = isValid("{{ subtract [c390c23a7f1b6441c98d2fe2a51248ef3].[total profit] [c390c23a7f1b6441c98d2fe2a51248ef3].[total revenue] }}") + expect(validity).toBe(true) + }) }) \ No newline at end of file