1
0
Fork 0
mirror of synced 2024-07-01 04:21:06 +12:00

Merge pull request #1824 from Budibase/fix/hbs-escape-issue

Fixing issue with HBS escaping/un-escaping strings
This commit is contained in:
Michael Drury 2021-06-24 12:27:27 +01:00 committed by GitHub
commit 2ab6c10ba3
3 changed files with 19 additions and 5 deletions

View file

@ -1,8 +1,8 @@
<!doctype html> <!doctype html>
<html> <html>
<head> <head>
{{{head}}} {{{head}}}
</head> </head>
<script> <script>

View file

@ -20,10 +20,13 @@ const HELPERS = [
// this help is applied to all statements // this help is applied to all statements
new Helper(HelperFunctionNames.ALL, value => { new Helper(HelperFunctionNames.ALL, value => {
// null/undefined values produce bad results // null/undefined values produce bad results
if (value == null) { if (value == null || typeof value !== "string") {
return "" return value || ""
} }
let text = new SafeString(unescape(value).replace(/&amp;/g, "&")) if (value && value.string) {
value = value.string
}
let text = new SafeString(value.replace(/&amp;/g, "&"))
if (text == null || typeof text !== "string") { if (text == null || typeof text !== "string") {
return text return text
} }

View file

@ -442,4 +442,15 @@ describe("Cover a few complex use cases", () => {
const output = await processObject(input, tableJson) const output = await processObject(input, tableJson)
expect(output.dataProvider).not.toBe("Invalid Binding") expect(output.dataProvider).not.toBe("Invalid Binding")
}) })
it("should be able to handle external ids", async () => {
const input = {
dataProvider: "{{ literal [_id] }}",
}
const context = {
_id: "%5B%221%22%2C%221%22%5D",
}
const output = await processObject(input, context)
expect(output.dataProvider).toBe("%5B%221%22%2C%221%22%5D")
})
}) })