Skip to content

Commit 1c1254b

Browse files
committed
Fix parsing of voidElements receiving children.
1 parent 1daffce commit 1c1254b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = function parse(html, options) {
3636
inComponent = true;
3737
}
3838

39-
if (!inComponent && nextChar && nextChar !== '<') {
39+
if (!current.voidElement && !inComponent && nextChar && nextChar !== '<') {
4040
current.children.push({
4141
type: 'text',
4242
content: html.slice(start, html.indexOf('<', start))

test/parse.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,28 @@ test('parse', function (t) {
270270
]
271271
}], 'should handle registered void tags if self-closing');
272272

273+
274+
html = '<div> 9 <input type="text"/> 10 </div>';
275+
parsed = HTML.parse(html);
276+
t.deepEqual(parsed, [{
277+
type: 'tag',
278+
name: 'div',
279+
attrs: {},
280+
voidElement: false,
281+
children: [
282+
{ type: 'text', content: ' 9 ' },
283+
{
284+
type: 'tag',
285+
name: 'input',
286+
attrs: {
287+
type: 'text'
288+
},
289+
children: [],
290+
voidElement: true,
291+
},
292+
{ type: 'text', content: ' 10 ' },
293+
]
294+
}], 'should not give voidElements children');
273295
t.end();
274296
});
275297

0 commit comments

Comments
 (0)