From 47f1d127316c84d07061f7a5088d3c5964e2e2c4 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Sun, 6 Dec 2015 13:12:41 -0800 Subject: [PATCH] fix(HtmlLexer): tag name must follow "<" without space see http://www.w3.org/TR/html5/syntax.html#tag-open-state --- modules/angular2/src/compiler/html_lexer.ts | 4 +++- modules/angular2/test/compiler/html_lexer_spec.ts | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/angular2/src/compiler/html_lexer.ts b/modules/angular2/src/compiler/html_lexer.ts index e3a725ce9d..f410fbdb73 100644 --- a/modules/angular2/src/compiler/html_lexer.ts +++ b/modules/angular2/src/compiler/html_lexer.ts @@ -378,7 +378,9 @@ class _HtmlTokenizer { let savedPos = this._savePosition(); let lowercaseTagName; try { - this._attemptUntilFn(isNotWhitespace); + if (!isAsciiLetter(this.peek)) { + throw this._createError(unexpectedCharacterErrorMsg(this.peek), this._getLocation()); + } var nameStart = this.index; this._consumeTagOpenStart(start); lowercaseTagName = this.inputLowercase.substring(nameStart, this.index); diff --git a/modules/angular2/test/compiler/html_lexer_spec.ts b/modules/angular2/test/compiler/html_lexer_spec.ts index 5d3f741156..5e61887eef 100644 --- a/modules/angular2/test/compiler/html_lexer_spec.ts +++ b/modules/angular2/test/compiler/html_lexer_spec.ts @@ -174,8 +174,8 @@ export function main() { ]); }); - it('should allow whitespace', () => { - expect(tokenizeAndHumanizeParts('< test >')) + it('should allow whitespace after the tag name', () => { + expect(tokenizeAndHumanizeParts('')) .toEqual([ [HtmlTokenType.TAG_OPEN_START, null, 'test'], [HtmlTokenType.TAG_OPEN_END], @@ -438,6 +438,9 @@ export function main() { [HtmlTokenType.TAG_CLOSE, '

'], [HtmlTokenType.EOF, ''], ]); + + expect(tokenizeAndHumanizeParts('< a>')) + .toEqual([[HtmlTokenType.TEXT, '< a>'], [HtmlTokenType.EOF]]); }); // TODO(vicb): make the lexer aware of Angular expressions