Skip to content

Commit

Permalink
fix(HtmlParser): mark <source> elements as void
Browse files Browse the repository at this point in the history
Fixes #5663
  • Loading branch information
pkozlowski-opensource committed Dec 7, 2015
1 parent 0a44fc6 commit 092e8a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
8 changes: 7 additions & 1 deletion modules/angular2/src/compiler/html_tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -357,7 +362,8 @@ 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(
{closedByChildren: ['col'], requiredParents: ['colgroup'], isVoid: true}),
'svg': new HtmlTagDefinition({implicitNamespacePrefix: 'svg'}),
'math': new HtmlTagDefinition({implicitNamespacePrefix: 'math'}),
'li': new HtmlTagDefinition({closedByChildren: ['li'], closedByParent: true}),
Expand Down
20 changes: 20 additions & 0 deletions modules/angular2/test/compiler/html_parser_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ 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:
// <base> - it can be present in head only
// <meta> - it can be present in head only
// <command> - obsolete
// <keygen> - obsolete

humanizeDom(parser.parse('<map><area></map>', 'TestComp'));
humanizeDom(parser.parse('<div><br></div>', 'TestComp'));
humanizeDom(parser.parse('<colgroup><col></colgroup>', 'TestComp'));
humanizeDom(parser.parse('<div><embed></div>', 'TestComp'));
humanizeDom(parser.parse('<div><hr></div>', 'TestComp'));
humanizeDom(parser.parse('<div><img></div>', 'TestComp'));
humanizeDom(parser.parse('<div><input></div>', 'TestComp'));
humanizeDom(parser.parse('<object><param>/<object>', 'TestComp'));
humanizeDom(parser.parse('<audio><source></audio>', 'TestComp'));
humanizeDom(parser.parse('<audio><track></audio>', 'TestComp'));
humanizeDom(parser.parse('<p><wbr></p>', 'TestComp'));
});

it('should close void elements on text nodes', () => {
expect(humanizeDom(parser.parse('<p>before<br>after</p>', 'TestComp')))
.toEqual([
Expand Down

0 comments on commit 092e8a0

Please sign in to comment.