File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 11/*jshint -W030 */
2- var tagRE = / < (?: " [ ^ " ] * " [ ' " ] * | ' [ ^ ' ] * ' [ ' " ] * | [ ^ ' " > ] ) + > / g;
2+ var tagRE = / (?: < ! - - [ \S \s ] * ? - - > | < (?: " [ ^ " ] * " [ ' " ] * | ' [ ^ ' ] * ' [ ' " ] * | [ ^ ' " > ] ) + > ) / g;
33var parseTag = require ( './parse-tag' ) ;
44// re-used obj for quick lookups of components
55var empty = Object . create ? Object . create ( null ) : { } ;
@@ -36,6 +36,10 @@ module.exports = function parse(html, options) {
3636 inComponent = false ;
3737 }
3838 }
39+ // check if this is a comment tag. if so, just return.
40+ if ( tag . indexOf ( '<!--' ) === 0 ) {
41+ return ;
42+ }
3943 var isOpen = tag . charAt ( 1 ) !== '/' ;
4044 var start = index + tag . length ;
4145 var nextChar = html . charAt ( start ) ;
Original file line number Diff line number Diff line change @@ -372,6 +372,36 @@ test('parse', function (t) {
372372 voidElement : false ,
373373 children : [ ]
374374 } ] , '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' ) ;
375405 t . end ( ) ;
376406} ) ;
377407
You can’t perform that action at this time.
0 commit comments