From 60a2ba87d4f8f6a69e80467adbc59d9fbce3577b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Bataille?= Date: Wed, 17 Feb 2016 14:52:51 +0100 Subject: [PATCH] fix(#7099): support for comment finishing with multiple dashes The issue came from a lack of support for backtracking on string matching. The way it is done, if the "end pattern" for consumeRawText starts with twice the same character, you end up having problem when your string being parsed has 3 times this char Example End string: xxyz string to parse: aaaaaaxxxyz calling consumeRawText(false, 'x', attemptParseStr('xyz')) would fail Closes #7119 --- modules/@angular/compiler/src/html_lexer.ts | 8 ++++++++ .../@angular/compiler/test/html_lexer_spec.ts | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/modules/@angular/compiler/src/html_lexer.ts b/modules/@angular/compiler/src/html_lexer.ts index bfd1cd7777..1c063539d8 100644 --- a/modules/@angular/compiler/src/html_lexer.ts +++ b/modules/@angular/compiler/src/html_lexer.ts @@ -267,8 +267,16 @@ class _HtmlTokenizer { } private _attemptStr(chars: string): boolean { + var indexBeforeAttempt = this.index; + var columnBeforeAttempt = this.column; + var lineBeforeAttempt = this.line; for (var i = 0; i < chars.length; i++) { if (!this._attemptCharCode(StringWrapper.charCodeAt(chars, i))) { + // If attempting to parse the string fails, we want to reset the parser + // to where it was before the attempt + this.index = indexBeforeAttempt; + this.column = columnBeforeAttempt; + this.line = lineBeforeAttempt; return false; } } diff --git a/modules/@angular/compiler/test/html_lexer_spec.ts b/modules/@angular/compiler/test/html_lexer_spec.ts index e0c08b045b..31089cbcc2 100644 --- a/modules/@angular/compiler/test/html_lexer_spec.ts +++ b/modules/@angular/compiler/test/html_lexer_spec.ts @@ -95,6 +95,26 @@ export function main() { expect(tokenizeAndHumanizeErrors('')) + .toEqual([ + [HtmlTokenType.COMMENT_START, ''], + [HtmlTokenType.EOF, ''] + ]); + }); + + it('should accept comments finishing by too many dashes (odd number)', () => { + expect(tokenizeAndHumanizeSourceSpans('')) + .toEqual([ + [HtmlTokenType.COMMENT_START, ''], + [HtmlTokenType.EOF, ''] + ]); + }); }); describe('doctype', () => {