Browse Source

Fixing issue with escaping on multiple bindings that are the same in queries.

pull/4549/head
mike12345567 5 years ago
parent
commit
3925fb3e31
  1. 9
      packages/string-templates/src/index.js
  2. 4
      packages/string-templates/test/basic.spec.js

9
packages/string-templates/src/index.js

@ -139,8 +139,13 @@ module.exports.disableEscaping = string => {
if (matches == null) {
return string
}
for (let match of matches) {
string = string.replace(match, `{${match}}`)
// find the unique set
const unique = [...new Set(matches)]
for (let match of unique) {
// add a negative lookahead to exclude any already
const regex = new RegExp(`${match}(?!})`, "g")
string = string.replace(regex, `{${match}}`)
}
return string
}

4
packages/string-templates/test/basic.spec.js

@ -194,5 +194,9 @@ describe("check that disabling escaping function works", () => {
it("should work with a combination", () => {
expect(disableEscaping("{{ name }} welcome to {{{ platform }}}")).toEqual("{{{ name }}} welcome to {{{ platform }}}")
})
it("should work with multiple escaped", () => {
expect(disableEscaping("{{ name }} welcome to {{ name }}")).toEqual("{{{ name }}} welcome to {{{ name }}}")
})
})

Loading…
Cancel
Save