From: Duncan Beevers Date: Tue, 2 Sep 2014 11:33:19 +0000 (-0500) Subject: script element with src must be preserved X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=71511166f583979539af10071c80d63a764da5dd;p=html-minifier.git script element with src must be preserved --- diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 52254f7..faf52ac 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -306,8 +306,20 @@ return false; } - function canRemoveElement(tag) { - return tag !== 'textarea'; + function canRemoveElement(tag, attrs) { + if (tag === 'textarea') { + return false; + } + + if (tag === 'script') { + for (var i = attrs.length - 1; i >= 0; i--) { + if (attrs[i].name === 'src') { + return false; + } + } + } + + return true; } function canCollapseWhitespace(tag) { @@ -556,7 +568,7 @@ buffer.push(token); } }, - end: function( tag ) { + end: function( tag, attrs ) { if (isIgnoring) { buffer.push(''); @@ -576,7 +588,7 @@ } var isElementEmpty = currentChars === '' && tag === currentTag; - if ((options.removeEmptyElements && isElementEmpty && canRemoveElement(tag))) { + if ((options.removeEmptyElements && isElementEmpty && canRemoveElement(tag, attrs))) { // remove last "element" from buffer, return for ( var i = buffer.length - 1; i >= 0; i-- ) { if ( /^<[^\/!]/.test(buffer[i]) ) { diff --git a/src/htmlparser.js b/src/htmlparser.js index 48aa66f..f3f755b 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -389,7 +389,7 @@ // Close all the open elements, up the stack for ( var i = stack.length - 1; i >= pos; i-- ) { if ( handler.end ) { - handler.end( stack[ i ].tag ); + handler.end( stack[ i ].tag, stack[ i ].attrs ); } }