From 50490b55eb41e63d6f192a8794c49d75cea822d9 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Mon, 7 Dec 2015 18:06:03 +0100 Subject: [PATCH] fix(HtmlParser): mark elements as void Fixes #5663 Closes #5668 --- modules/angular2/src/compiler/html_tags.ts | 7 ++++++- modules/angular2/test/compiler/html_parser_spec.ts | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/angular2/src/compiler/html_tags.ts b/modules/angular2/src/compiler/html_tags.ts index 1253b94ae2..e393a0da5c 100644 --- a/modules/angular2/src/compiler/html_tags.ts +++ b/modules/angular2/src/compiler/html_tags.ts @@ -310,11 +310,16 @@ export class HtmlTagDefinition { // see http://www.w3.org/TR/html51/syntax.html#optional-tags // This implementation does not fully conform to the HTML5 spec. var TAG_DEFINITIONS: {[key: string]: HtmlTagDefinition} = { + 'area': new HtmlTagDefinition({isVoid: true}), + 'embed': new HtmlTagDefinition({isVoid: true}), 'link': new HtmlTagDefinition({isVoid: true}), 'img': new HtmlTagDefinition({isVoid: true}), 'input': new HtmlTagDefinition({isVoid: true}), + 'param': new HtmlTagDefinition({isVoid: true}), 'hr': new HtmlTagDefinition({isVoid: true}), 'br': new HtmlTagDefinition({isVoid: true}), + 'source': new HtmlTagDefinition({isVoid: true}), + 'track': new HtmlTagDefinition({isVoid: true}), 'wbr': new HtmlTagDefinition({isVoid: true}), 'p': new HtmlTagDefinition({ closedByChildren: [ @@ -357,7 +362,7 @@ var TAG_DEFINITIONS: {[key: string]: HtmlTagDefinition} = { }), 'td': new HtmlTagDefinition({closedByChildren: ['td', 'th'], closedByParent: true}), 'th': new HtmlTagDefinition({closedByChildren: ['td', 'th'], closedByParent: true}), - 'col': new HtmlTagDefinition({closedByChildren: ['col'], requiredParents: ['colgroup']}), + 'col': new HtmlTagDefinition({requiredParents: ['colgroup'], isVoid: true}), 'svg': new HtmlTagDefinition({implicitNamespacePrefix: 'svg'}), 'math': new HtmlTagDefinition({implicitNamespacePrefix: 'math'}), 'li': new HtmlTagDefinition({closedByChildren: ['li'], closedByParent: true}), diff --git a/modules/angular2/test/compiler/html_parser_spec.ts b/modules/angular2/test/compiler/html_parser_spec.ts index fd55214414..eb709c6113 100644 --- a/modules/angular2/test/compiler/html_parser_spec.ts +++ b/modules/angular2/test/compiler/html_parser_spec.ts @@ -75,6 +75,19 @@ export function main() { ]); }); + it('should not error on void elements from HTML5 spec', + () => { // http://www.w3.org/TR/html-markup/syntax.html#syntax-elements without: + // - it can be present in head only + // - it can be present in head only + // - obsolete + // - obsolete + ['', '

', '', + '
', '

', '
', '
', + '/', '', '', + '

', + ].forEach((html) => { expect(parser.parse(html, 'TestComp').errors).toEqual([]); }); + }); + it('should close void elements on text nodes', () => { expect(humanizeDom(parser.parse('

before
after

', 'TestComp'))) .toEqual([