Skip to content

Commit b56ebb5

Browse files
committed
Handle multiple & nested comments in a string.
1 parent 3b4e3c1 commit b56ebb5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*jshint -W030 */
2-
var tagRE = /(?:<!--[\S\s]*-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g;
2+
var tagRE = /(?:<!--[\S\s]*?-->|<(?:"[^"]*"['"]*|'[^']*'['"]*|[^'">])+>)/g;
33
var parseTag = require('./parse-tag');
44
// re-used obj for quick lookups of components
55
var empty = Object.create ? Object.create(null) : {};

test/parse.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,24 @@ test('parse', function (t) {
378378
{ type: 'text', content: 'Hi'}
379379
]
380380
}], 'should ignore HTML comments');
381+
382+
html = '<div>Hi <!-- I\'m a nested comment! with a <span></span> --></div><span><!--test--></span>';
383+
parsed = HTML.parse(html);
384+
t.deepEqual(parsed, [{
385+
type: 'tag',
386+
name: 'div',
387+
attrs: {},
388+
voidElement: false,
389+
children: [
390+
{ type: 'text', content: 'Hi '}
391+
]
392+
},{
393+
type: 'tag',
394+
name: 'span',
395+
attrs: {},
396+
voidElement: false,
397+
children: []
398+
}], 'should ignore nested HTML comments');
381399
t.end();
382400
});
383401

0 commit comments

Comments
 (0)