Skip to content

Commit 3b4e3c1

Browse files
committed
Catch when we're dealing with a comment and just ignore it.
1 parent 7caf311 commit 3b4e3c1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/parse.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ module.exports = function parse(html, options) {
2222
inComponent = false;
2323
}
2424
}
25+
// check if this is a comment tag. if so, just return.
26+
if (tag.indexOf('<!--') === 0) {
27+
return;
28+
}
2529
var isOpen = tag.charAt(1) !== '/';
2630
var start = index + tag.length;
2731
var nextChar = html.charAt(start);

test/parse.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,18 @@ test('parse', function (t) {
366366
{ type: 'text', content: 'There' }
367367
]
368368
}], 'should remove text nodes that are nothing but whitespace');
369+
370+
html = '<!--\n\t<style type="text/css">\n\t\t.header {\n\t\t\tfont-size: 14px;\n\t\t}\n\t</style>\n\n-->\n<div>Hi</div>';
371+
parsed = HTML.parse(html);
372+
t.deepEqual(parsed, [{
373+
type: 'tag',
374+
name: 'div',
375+
attrs: {},
376+
voidElement: false,
377+
children: [
378+
{ type: 'text', content: 'Hi'}
379+
]
380+
}], 'should ignore HTML comments');
369381
t.end();
370382
});
371383

0 commit comments

Comments
 (0)