Skip to content

Commit 47f1d12

Browse files
committed
fix(HtmlLexer): tag name must follow "<" without space
see http://www.w3.org/TR/html5/syntax.html#tag-open-state
1 parent aecf681 commit 47f1d12

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

modules/angular2/src/compiler/html_lexer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,9 @@ class _HtmlTokenizer {
378378
let savedPos = this._savePosition();
379379
let lowercaseTagName;
380380
try {
381-
this._attemptUntilFn(isNotWhitespace);
381+
if (!isAsciiLetter(this.peek)) {
382+
throw this._createError(unexpectedCharacterErrorMsg(this.peek), this._getLocation());
383+
}
382384
var nameStart = this.index;
383385
this._consumeTagOpenStart(start);
384386
lowercaseTagName = this.inputLowercase.substring(nameStart, this.index);

modules/angular2/test/compiler/html_lexer_spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ export function main() {
174174
]);
175175
});
176176

177-
it('should allow whitespace', () => {
178-
expect(tokenizeAndHumanizeParts('< test >'))
177+
it('should allow whitespace after the tag name', () => {
178+
expect(tokenizeAndHumanizeParts('<test >'))
179179
.toEqual([
180180
[HtmlTokenType.TAG_OPEN_START, null, 'test'],
181181
[HtmlTokenType.TAG_OPEN_END],
@@ -438,6 +438,9 @@ export function main() {
438438
[HtmlTokenType.TAG_CLOSE, '</p>'],
439439
[HtmlTokenType.EOF, ''],
440440
]);
441+
442+
expect(tokenizeAndHumanizeParts('< a>'))
443+
.toEqual([[HtmlTokenType.TEXT, '< a>'], [HtmlTokenType.EOF]]);
441444
});
442445

443446
// TODO(vicb): make the lexer aware of Angular expressions

0 commit comments

Comments
 (0)