Skip to content

Commit

Permalink
fixup! fix(compiler): handle strings inside bindings that contain bin…
Browse files Browse the repository at this point in the history
…ding characters
  • Loading branch information
crisbeto committed Nov 25, 2020
1 parent 1816113 commit 1512e3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 2 additions & 4 deletions packages/compiler/src/expression_parser/parser.ts
Expand Up @@ -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;
}
}
Expand Down
12 changes: 12 additions & 0 deletions packages/compiler/test/template_parser/template_parser_spec.ts
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 1512e3b

Please sign in to comment.