diff --git a/extensions/amp-analytics/0.1/variables.js b/extensions/amp-analytics/0.1/variables.js index 907cea00cc352..91a329e904721 100644 --- a/extensions/amp-analytics/0.1/variables.js +++ b/extensions/amp-analytics/0.1/variables.js @@ -395,7 +395,7 @@ export class VariableService { * @return {!Promise} The expanded string. */ expandTemplate(template, options, element, opt_bindings, opt_allowlist) { - return asyncStringReplace(template, /\${([^}]*)}/g, (match, key) => { + return asyncStringReplace(template, /\${([^{}]*)}/g, (match, key) => { if (options.iterations < 0) { user().error( TAG, diff --git a/src/core/types/string/index.js b/src/core/types/string/index.js index 75793259b4b9d..e4ce03e361670 100644 --- a/src/core/types/string/index.js +++ b/src/core/types/string/index.js @@ -89,7 +89,7 @@ export function expandTemplate(template, getter, opt_maxIterations) { const maxIterations = opt_maxIterations || 1; for (let i = 0; i < maxIterations; i++) { let matches = 0; - template = template.replace(/\${([^}]*)}/g, (_a, b) => { + template = template.replace(/\${([^{}]*)}/g, (_a, b) => { matches++; return getter(b); }); diff --git a/test/unit/core/types/string/test-string.js b/test/unit/core/types/string/test-string.js index 6387c4ffc72ba..77cd526923f15 100644 --- a/test/unit/core/types/string/test-string.js +++ b/test/unit/core/types/string/test-string.js @@ -89,7 +89,8 @@ describes.sandboxed('type helpers - strings', {}, () => { expect(expandTemplate('$x}', testGetter)).to.equal('$x}'); expect(expandTemplate('$x', testGetter)).to.equal('$x'); expect(expandTemplate('{x}', testGetter)).to.equal('{x}'); - expect(expandTemplate('${{x}', testGetter)).to.equal('not found'); + expect(expandTemplate('${{x}', testGetter)).to.equal('${{x}'); + expect(expandTemplate('${${x}', testGetter)).to.equal('${Test 1'); }); it('should default to one iteration.', () => {