From 8e35978101ac754ba75a0591d6d142b4c235b3c3 Mon Sep 17 00:00:00 2001 From: Juriy Zaytsev Date: Mon, 8 Feb 2010 08:40:07 -0500 Subject: [PATCH] Add test for empty attributes. Add more empty "attributes" to the list (onfocus, onchange, onblur). --- src/htmlminifier.js | 7 +++++-- tests/index.html | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) 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 -- 2.34.1