Skip to content

Commit 50490b5

Browse files
fix(HtmlParser): mark <source> elements as void
Fixes angular#5663 Closes angular#5668
1 parent 86c74cf commit 50490b5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

modules/angular2/src/compiler/html_tags.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,16 @@ export class HtmlTagDefinition {
310310
// see http://www.w3.org/TR/html51/syntax.html#optional-tags
311311
// This implementation does not fully conform to the HTML5 spec.
312312
var TAG_DEFINITIONS: {[key: string]: HtmlTagDefinition} = {
313+
'area': new HtmlTagDefinition({isVoid: true}),
314+
'embed': new HtmlTagDefinition({isVoid: true}),
313315
'link': new HtmlTagDefinition({isVoid: true}),
314316
'img': new HtmlTagDefinition({isVoid: true}),
315317
'input': new HtmlTagDefinition({isVoid: true}),
318+
'param': new HtmlTagDefinition({isVoid: true}),
316319
'hr': new HtmlTagDefinition({isVoid: true}),
317320
'br': new HtmlTagDefinition({isVoid: true}),
321+
'source': new HtmlTagDefinition({isVoid: true}),
322+
'track': new HtmlTagDefinition({isVoid: true}),
318323
'wbr': new HtmlTagDefinition({isVoid: true}),
319324
'p': new HtmlTagDefinition({
320325
closedByChildren: [
@@ -357,7 +362,7 @@ var TAG_DEFINITIONS: {[key: string]: HtmlTagDefinition} = {
357362
}),
358363
'td': new HtmlTagDefinition({closedByChildren: ['td', 'th'], closedByParent: true}),
359364
'th': new HtmlTagDefinition({closedByChildren: ['td', 'th'], closedByParent: true}),
360-
'col': new HtmlTagDefinition({closedByChildren: ['col'], requiredParents: ['colgroup']}),
365+
'col': new HtmlTagDefinition({requiredParents: ['colgroup'], isVoid: true}),
361366
'svg': new HtmlTagDefinition({implicitNamespacePrefix: 'svg'}),
362367
'math': new HtmlTagDefinition({implicitNamespacePrefix: 'math'}),
363368
'li': new HtmlTagDefinition({closedByChildren: ['li'], closedByParent: true}),

modules/angular2/test/compiler/html_parser_spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,19 @@ export function main() {
7575
]);
7676
});
7777

78+
it('should not error on void elements from HTML5 spec',
79+
() => { // http://www.w3.org/TR/html-markup/syntax.html#syntax-elements without:
80+
// <base> - it can be present in head only
81+
// <meta> - it can be present in head only
82+
// <command> - obsolete
83+
// <keygen> - obsolete
84+
['<map><area></map>', '<div><br></div>', '<colgroup><col></colgroup>',
85+
'<div><embed></div>', '<div><hr></div>', '<div><img></div>', '<div><input></div>',
86+
'<object><param>/<object>', '<audio><source></audio>', '<audio><track></audio>',
87+
'<p><wbr></p>',
88+
].forEach((html) => { expect(parser.parse(html, 'TestComp').errors).toEqual([]); });
89+
});
90+
7891
it('should close void elements on text nodes', () => {
7992
expect(humanizeDom(parser.parse('<p>before<br>after</p>', 'TestComp')))
8093
.toEqual([

0 commit comments

Comments
 (0)