Browse Source
Merge pull request #1073 from Budibase/bug/quick-handlebars-fix
Bug/quick handlebars fix
gh-pages
Martin McKeaveney
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
9 additions and
2 deletions
-
packages/string-templates/src/index.js
-
packages/string-templates/test/helpers.spec.js
|
|
@ -110,7 +110,7 @@ module.exports.makePropSafe = property => { |
|
|
* @returns {boolean} Whether or not the input string is valid. |
|
|
* @returns {boolean} Whether or not the input string is valid. |
|
|
*/ |
|
|
*/ |
|
|
module.exports.isValid = string => { |
|
|
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
|
|
|
// don't really need a real context to check if its valid
|
|
|
const context = {} |
|
|
const context = {} |
|
|
try { |
|
|
try { |
|
|
@ -118,7 +118,9 @@ module.exports.isValid = string => { |
|
|
return true |
|
|
return true |
|
|
} catch (err) { |
|
|
} catch (err) { |
|
|
const msg = err ? err.message : "" |
|
|
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
|
|
|
// special case for maths functions - don't have inputs yet
|
|
|
return !!foundCase |
|
|
return !!foundCase |
|
|
} |
|
|
} |
|
|
|
|
|
@ -311,4 +311,9 @@ describe("Cover a few complex use cases", () => { |
|
|
const output = await processString(`{{first ( split "a-b-c" "-") 2}}`, {}) |
|
|
const output = await processString(`{{first ( split "a-b-c" "-") 2}}`, {}) |
|
|
expect(output).toBe(`a,b`) |
|
|
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) |
|
|
|
|
|
}) |
|
|
}) |
|
|
}) |