From: Mathias Bynens Date: Tue, 14 May 2013 16:33:08 +0000 (+0200) Subject: Improve `canRemoveAttributeQuotes` X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=9a084fe350a63a4486e7e7f28128dc4345217f0d;p=html-minifier.git Improve `canRemoveAttributeQuotes` See http://mathiasbynens.be/notes/unquoted-attribute-values for how browsers behave when it comes to unquoted attribute values, and what the HTML spec (based on pre-existing behavior) says about it. Closes #60 and #61. --- diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 457e3a3..eafb599 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -71,9 +71,8 @@ } function canRemoveAttributeQuotes(value) { - // http://www.w3.org/TR/html4/intro/sgmltut.html#attributes - // avoid \w, which could match unicode in some implementations - return (/^[a-zA-Z0-9-._:]+$/).test(value); + // http://mathiasbynens.be/notes/unquoted-attribute-values + return /^[^\x20\t\n\f\r"'`=<>]+$/.test(value); } function attributesInclude(attributes, attribute) { diff --git a/tests/minifier.js b/tests/minifier.js index c950245..5f65f35 100644 --- a/tests/minifier.js +++ b/tests/minifier.js @@ -440,10 +440,13 @@ equal(minify(input, { removeAttributeQuotes: true }), ''); input = 'x'; - equal(minify(input, { removeAttributeQuotes: true }), 'x'); + equal(minify(input, { removeAttributeQuotes: true }), 'x'); - input = '\nfoo\n\n'; - equal(minify(input, { removeAttributeQuotes: true }), '\nfoo\n\n'); + input = '\nfoo\n\n'; + equal(minify(input, { removeAttributeQuotes: true }), '\nfoo\n\n'); + + input = '

'; + equal(minify(input, { removeAttributeQuotes: true }), '

'); }); test('collapsing whitespace', function() {