Skip to content

Commit

Permalink
fix(#7099): support for comment finishing with multiple dashes
Browse files Browse the repository at this point in the history
<!-- xxxx ------->

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
  • Loading branch information
gbataille authored and mhevery committed May 25, 2016
1 parent 83c19a1 commit 60a2ba8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions modules/@angular/compiler/src/html_lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
20 changes: 20 additions & 0 deletions modules/@angular/compiler/test/html_lexer_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ export function main() {
expect(tokenizeAndHumanizeErrors('<!--'))
.toEqual([[HtmlTokenType.RAW_TEXT, 'Unexpected character "EOF"', '0:4']]);
});

it('should accept comments finishing by too many dashes (even number)', () => {
expect(tokenizeAndHumanizeSourceSpans('<!-- test ---->'))
.toEqual([
[HtmlTokenType.COMMENT_START, '<!--'],
[HtmlTokenType.RAW_TEXT, ' test --'],
[HtmlTokenType.COMMENT_END, '-->'],
[HtmlTokenType.EOF, '']
]);
});

it('should accept comments finishing by too many dashes (odd number)', () => {
expect(tokenizeAndHumanizeSourceSpans('<!-- test --->'))
.toEqual([
[HtmlTokenType.COMMENT_START, '<!--'],
[HtmlTokenType.RAW_TEXT, ' test -'],
[HtmlTokenType.COMMENT_END, '-->'],
[HtmlTokenType.EOF, '']
]);
});
});

describe('doctype', () => {
Expand Down

0 comments on commit 60a2ba8

Please sign in to comment.