File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 1
1
/*jshint -W030 */
2
- var tagRE = / < (?: " [ ^ " ] * " [ ' " ] * | ' [ ^ ' ] * ' [ ' " ] * | [ ^ ' " > ] ) + > / g;
2
+ var tagRE = / (?: < ! - - [ \S \s ] * ? - - > | < (?: " [ ^ " ] * " [ ' " ] * | ' [ ^ ' ] * ' [ ' " ] * | [ ^ ' " > ] ) + > ) / g;
3
3
var parseTag = require ( './parse-tag' ) ;
4
4
// re-used obj for quick lookups of components
5
5
var empty = Object . create ? Object . create ( null ) : { } ;
@@ -36,6 +36,10 @@ module.exports = function parse(html, options) {
36
36
inComponent = false ;
37
37
}
38
38
}
39
+ // check if this is a comment tag. if so, just return.
40
+ if ( tag . indexOf ( '<!--' ) === 0 ) {
41
+ return ;
42
+ }
39
43
var isOpen = tag . charAt ( 1 ) !== '/' ;
40
44
var start = index + tag . length ;
41
45
var nextChar = html . charAt ( start ) ;
Original file line number Diff line number Diff line change @@ -372,6 +372,36 @@ test('parse', function (t) {
372
372
voidElement : false ,
373
373
children : [ ]
374
374
} ] , 'should remove text nodes that are nothing but whitespace' ) ;
375
+
376
+ 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>' ;
377
+ parsed = HTML . parse ( html ) ;
378
+ t . deepEqual ( parsed , [ {
379
+ type : 'tag' ,
380
+ name : 'div' ,
381
+ attrs : { } ,
382
+ voidElement : false ,
383
+ children : [
384
+ { type : 'text' , content : 'Hi' }
385
+ ]
386
+ } ] , 'should ignore HTML comments' ) ;
387
+
388
+ html = '<div>Hi <!-- I\'m a nested comment! with a <span></span> --></div><span><!--test--></span>' ;
389
+ parsed = HTML . parse ( html ) ;
390
+ t . deepEqual ( parsed , [ {
391
+ type : 'tag' ,
392
+ name : 'div' ,
393
+ attrs : { } ,
394
+ voidElement : false ,
395
+ children : [
396
+ { type : 'text' , content : 'Hi ' }
397
+ ]
398
+ } , {
399
+ type : 'tag' ,
400
+ name : 'span' ,
401
+ attrs : { } ,
402
+ voidElement : false ,
403
+ children : [ ]
404
+ } ] , 'should ignore nested HTML comments' ) ;
375
405
t . end ( ) ;
376
406
} ) ;
377
407
You can’t perform that action at this time.
0 commit comments