@@ -67,22 +67,30 @@ var defaultCbs = {
6767 */
6868} ;
6969
70- var formTags = { 'input' :1 , 'option' :1 , 'optgroup' :1 , 'select' :1 , 'button' :1 , 'datalist' :1 , 'textarea' :1 } ;
70+ var formTags = {
71+ input : true ,
72+ option : true ,
73+ optgroup : true ,
74+ select : true ,
75+ button : true ,
76+ datalist : true ,
77+ textarea : true
78+ } ;
7179var openImpliesClose = {
72- 'tr' : { 'tr' : 1 , 'th' : 1 , 'td' : 1 } ,
73- 'th' : { 'th' : 1 } ,
74- 'td' : { ' thead' : 1 , 'td' : 1 } ,
75- ' body' : { ' head' : 1 , ' link' : 1 , ' script' : 1 } ,
76- 'li' : { 'li' : 1 } ,
77- 'p' : { 'p' : 1 } ,
78- ' select' : formTags ,
79- ' input' : formTags ,
80- ' output' : formTags ,
81- ' button' : formTags ,
82- ' datalist' : formTags ,
83- ' textarea' : formTags ,
84- ' option' : { ' option' : 1 } ,
85- ' optgroup' : { ' optgroup' : 1 }
80+ tr : { tr : true , th : true , td : true } ,
81+ th : { th : true } ,
82+ td : { thead : true , td : true } ,
83+ body : { head : true , link : true , script : true } ,
84+ li : { li : true } ,
85+ p : { p : true } ,
86+ select : formTags ,
87+ input : formTags ,
88+ output : formTags ,
89+ button : formTags ,
90+ datalist : formTags ,
91+ textarea : formTags ,
92+ option : { option : true } ,
93+ optgroup : { optgroup : true }
8694} ;
8795
8896//Parses a complete HTML and pushes it to the handler
@@ -350,7 +358,7 @@ Parser.prototype._processOpenTag = function(data){
350358 if ( this . _options . xmlMode ) { /*do nothing*/ }
351359 else if ( name === "script" ) type = ElementType . Script ;
352360 else if ( name === "style" ) type = ElementType . Style ;
353- if ( name in openImpliesClose ) {
361+ if ( ! this . _options . xmlMode && name in openImpliesClose ) {
354362 var el ;
355363 while ( ( el = this . _stack [ this . _stack . length - 1 ] ) in openImpliesClose [ name ] ) {
356364 this . _processCloseTag ( el ) ;
@@ -369,7 +377,7 @@ Parser.prototype._processOpenTag = function(data){
369377 * Invalid HTML self-closing tag syntax is ignored (treated as an opening tag).
370378 * Foreign elements use XML rules
371379 */
372- if ( ! Object . keys ( attributes ) . length && data . substr ( - 1 ) === "/" || ( name in emptyTags && ! this . _options . xmlMode ) ) {
380+ if ( ( ! this . _options . xmlMode && name in emptyTags ) || ( data . substr ( - 1 ) === "/" && data . replace ( _reAttrib , "" ) . substr ( - 1 ) === "/" ) ) {
373381 if ( this . _cbs . onclosetag ) this . _cbs . onclosetag ( name ) ;
374382 } else {
375383 if ( type !== ElementType . Tag ) {
@@ -386,4 +394,4 @@ Parser.prototype._handleError = function(error){
386394 else throw error ;
387395} ;
388396
389- module . exports = Parser ;
397+ module . exports = Parser ;
0 commit comments