Add test for empty attributes.
authorJuriy Zaytsev <kangax@gmail.com>
Mon, 8 Feb 2010 13:40:07 +0000 (08:40 -0500)
committerJuriy Zaytsev <kangax@gmail.com>
Mon, 8 Feb 2010 13:40:07 +0000 (08:40 -0500)
Add more empty "attributes" to the list (onfocus, onchange, onblur).

src/htmlminifier.js
tests/index.html

index 9874384..93521cd 100644 (file)
     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;
   }
index 30c4234..2799d16 100644 (file)
           equals(minify(input, { shouldRemoveComments: true }), input);
         });
         
+        test('empty attributes', function(){
+          var input = '<p id="" class="" style=" " title="\n" lang="" dir="">x</p>';
+          equals(minify(input, { shouldRemoveEmptyAttributes: true }), '<p>x</p>');
+          
+          input = '<p onclick=""   ondblclick=" " onmousedown="" onmouseup="" onmouseover=" " onmousemove="" onmouseout="" '+
+                  'onkeypress=\n\n  "\n     " onkeydown=\n"" onkeyup\n="">x</p>';
+          equals(minify(input, { shouldRemoveEmptyAttributes: true }), '<p>x</p>');
+          
+          input = '<input onfocus="" onblur="" onchange=" " value=" boo ">';
+          equals(minify(input, { shouldRemoveEmptyAttributes: true }), '<input value=" boo ">');
+          
+          input = '<input value="" name="foo">';
+          equals(minify(input, { shouldRemoveEmptyAttributes: true }), '<input name="foo">');
+        });
+        
       })(this);
     </script>
+    <input type="input" title=" ">
   </body>
 </html>
\ No newline at end of file