From: Duncan Beevers Date: Sat, 26 Jul 2014 21:10:03 +0000 (-0500) Subject: Splay out attribute recognizer X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=ab819705fe96960374e9e3fe24f0677977286190;p=html-minifier.git Splay out attribute recognizer --- diff --git a/src/htmlparser.js b/src/htmlparser.js index 35435fd..70895b4 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -37,7 +37,13 @@ startTagClose = /\s*(\/?)>/, endTag = /^<\/([\w:-]+)[^>]*>/, endingSlash = /\/>$/, - singleAttr = /([\w:-]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/, + singleAttrIdentifier = /([\w:-]+)/, + singleAttrAssign = /=/, + singleAttrValues = [ + /"((?:\\.|[^"])*)"/.source, // attr value double quotes + /'((?:\\.|[^'])*)'/.source, // attr value, single quotes + /([^>\s]+)/.source // attr value, no quotes + ], doctype = /^]+>/i, startIgnore = /<(%|\?)/, endIgnore = /(%|\?)>/; @@ -92,6 +98,17 @@ } function attrForHandler( handler ) { + var singleAttr = new RegExp( + singleAttrIdentifier.source + + '(?:\\s*' + + singleAttrAssign.source + + '\\s*' + + '(?:' + + singleAttrValues.join('|') + + ')' + + ')?' + ); + if ( handler.customAttrSurround ) { var attrClauses = []; for ( var i = handler.customAttrSurround.length - 1; i >= 0; i-- ) {