fix(#7099): support for comment finishing with multiple dashes
<!-- 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
This commit is contained in:
parent
83c19a1fbc
commit
60a2ba87d4
|
@ -267,8 +267,16 @@ class _HtmlTokenizer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private _attemptStr(chars: string): boolean {
|
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++) {
|
for (var i = 0; i < chars.length; i++) {
|
||||||
if (!this._attemptCharCode(StringWrapper.charCodeAt(chars, 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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,6 +95,26 @@ export function main() {
|
||||||
expect(tokenizeAndHumanizeErrors('<!--'))
|
expect(tokenizeAndHumanizeErrors('<!--'))
|
||||||
.toEqual([[HtmlTokenType.RAW_TEXT, 'Unexpected character "EOF"', '0:4']]);
|
.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', () => {
|
describe('doctype', () => {
|
||||||
|
|
Loading…
Reference in New Issue