From 6f281ab3c47a7ac204726a3d71cbbcfe8b923324 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Fri, 3 Jun 2016 19:49:17 +0200 Subject: [PATCH] fix(HTMLParser): properly report errors for not properly closed tags (#8999) Fixes #7849 --- modules/@angular/compiler/src/html_parser.ts | 4 +++- modules/@angular/compiler/test/html_parser_spec.ts | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/@angular/compiler/src/html_parser.ts b/modules/@angular/compiler/src/html_parser.ts index 0611c3197d..141b6f94b3 100644 --- a/modules/@angular/compiler/src/html_parser.ts +++ b/modules/@angular/compiler/src/html_parser.ts @@ -295,7 +295,9 @@ class TreeBuilder { var fullName = getElementFullName(endTagToken.parts[0], endTagToken.parts[1], this._getParentElement()); - this._getParentElement().endSourceSpan = endTagToken.sourceSpan; + if (this._getParentElement()) { + this._getParentElement().endSourceSpan = endTagToken.sourceSpan; + } if (getHtmlTagDefinition(fullName).isVoid) { this.errors.push( diff --git a/modules/@angular/compiler/test/html_parser_spec.ts b/modules/@angular/compiler/test/html_parser_spec.ts index 2466b65520..d6067dc4fd 100644 --- a/modules/@angular/compiler/test/html_parser_spec.ts +++ b/modules/@angular/compiler/test/html_parser_spec.ts @@ -343,6 +343,12 @@ export function main() { expect(humanizeErrors(errors)).toEqual([['p', 'Unexpected closing tag "p"', '0:5']]); }); + it('should report subsequent open tags without proper close tag', () => { + let errors = parser.parse('', 'TestComp').errors; + expect(errors.length).toEqual(1); + expect(humanizeErrors(errors)).toEqual([['div', 'Unexpected closing tag "div"', '0:4']]); + }); + it('should report closing tag for void elements', () => { let errors = parser.parse('', 'TestComp').errors; expect(errors.length).toEqual(1);