diff --git a/packages/string-templates/src/index.js b/packages/string-templates/src/index.js index c0b5563f3d..41dd7381ad 100644 --- a/packages/string-templates/src/index.js +++ b/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 } diff --git a/packages/string-templates/test/basic.spec.js b/packages/string-templates/test/basic.spec.js index c5aac2a628..fbd1c5f440 100644 --- a/packages/string-templates/test/basic.spec.js +++ b/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 }}}") + }) })