From: Juriy Zaytsev Date: Mon, 8 Feb 2010 13:40:07 +0000 (-0500) Subject: Add test for empty attributes. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=8e35978101ac754ba75a0591d6d142b4c235b3c3;p=html-minifier.git Add test for empty attributes. Add more empty "attributes" to the list (onfocus, onchange, onblur). --- diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 9874384..93521cd 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -68,6 +68,10 @@ return attrValue; } + var reEmptyAttribute = new RegExp( + '^(?:class|id|style|title|lang|dir|on(?:focus|blur|change|click|dblclick|mouse(' + + '?:down|up|over|move|out)|key(?:press|down|up)))$'); + function canDeleteEmptyAttribute(tag, attrName, attrValue) { var isValueEmpty = /^(["'])?\s*\1$/.test(attrValue); @@ -80,8 +84,7 @@ return ( (tag === 'input' && attrName === 'value') || - /^(?:class|id|style|title|lang|dir|on(?:click|dblclick|mouse(?:down|up|over|move|out)|key(?:press|down|up)))$/.test(attrName) - ); + reEmptyAttribute.test(attrName)); } return false; } diff --git a/tests/index.html b/tests/index.html index 30c4234..2799d16 100644 --- a/tests/index.html +++ b/tests/index.html @@ -64,7 +64,23 @@ equals(minify(input, { shouldRemoveComments: true }), input); }); + test('empty attributes', function(){ + var input = '

x

'; + equals(minify(input, { shouldRemoveEmptyAttributes: true }), '

x

'); + + input = '

x

'; + equals(minify(input, { shouldRemoveEmptyAttributes: true }), '

x

'); + + input = ''; + equals(minify(input, { shouldRemoveEmptyAttributes: true }), ''); + + input = ''; + equals(minify(input, { shouldRemoveEmptyAttributes: true }), ''); + }); + })(this); + \ No newline at end of file