diff --git a/packages/compiler/src/expression_parser/parser.ts b/packages/compiler/src/expression_parser/parser.ts index f690d7b45659d5..4a2cbfbaaafc71 100644 --- a/packages/compiler/src/expression_parser/parser.ts +++ b/packages/compiler/src/expression_parser/parser.ts @@ -348,13 +348,11 @@ export class Parser { for (let i = start; i < input.length; i++) { const char = input[i]; // Skip the characters inside quotes. Note that we only care about the - // outer-most quotes matching up and we need to account for escape characters. + // outer-most quotes matching up and we need to account for escape characters. if (isQuote(input.charCodeAt(i)) && (currentQuote === null || currentQuote === char) && input[i - 1] !== '\\') { currentQuote = currentQuote === null ? char : null; - } else if ( - currentQuote === null && char === value[0] && - (valueLength === 0 || input.substring(i, i + valueLength) === value)) { + } else if (currentQuote === null && char === value[0] && input.startsWith(value, i)) { return i; } } diff --git a/packages/compiler/test/template_parser/template_parser_spec.ts b/packages/compiler/test/template_parser/template_parser_spec.ts index efd999205b242a..245ae8e93bba0d 100644 --- a/packages/compiler/test/template_parser/template_parser_spec.ts +++ b/packages/compiler/test/template_parser/template_parser_spec.ts @@ -546,12 +546,24 @@ describe('TemplateParser', () => { it('should parse bound text nodes with interpolations inside quotes', () => { expect(humanizeTplAst(parse('{{ "{{a}}" }}', []))).toEqual([[BoundTextAst, '{{ "{{a}}" }}']]); + expect(humanizeTplAst(parse('{{"{{"}}', []))).toEqual([[BoundTextAst, '{{ "{{" }}']]); + expect(humanizeTplAst(parse('{{"}}"}}', []))).toEqual([[BoundTextAst, '{{ "}}" }}']]); + expect(humanizeTplAst(parse('{{"{"}}', []))).toEqual([[BoundTextAst, '{{ "{" }}']]); + expect(humanizeTplAst(parse('{{"}"}}', []))).toEqual([[BoundTextAst, '{{ "}" }}']]); }); it('should parse bound text nodes with escaped quotes', () => { expect(humanizeTplAst(parse(`{{'It\\'s just Angular'}}`, []))).toEqual([ [BoundTextAst, `{{ "It's just Angular" }}`] ]); + + expect(humanizeTplAst(parse(`{{'It\\'s {{ just Angular'}}`, []))).toEqual([ + [BoundTextAst, `{{ "It's {{ just Angular" }}`] + ]); + + expect(humanizeTplAst(parse(`{{'It\\'s }} just Angular'}}`, []))).toEqual([ + [BoundTextAst, `{{ "It's }} just Angular" }}`] + ]); }); it('should not parse bound text nodes with mismatching quotes', () => {