Collapse whitespace in class attributes to 1 space (not only trim).
authorJuriy Zaytsev <kangax@gmail.com>
Mon, 8 Feb 2010 23:57:34 +0000 (18:57 -0500)
committerJuriy Zaytsev <kangax@gmail.com>
Mon, 8 Feb 2010 23:57:34 +0000 (18:57 -0500)
src/htmlminifier.js
tests/index.html

index 4615877..6a4bda9 100644 (file)
@@ -66,7 +66,8 @@
       return attrValue.replace(/^(['"])?javascript:/i, '$1');
     }
     if (attrName.toLowerCase() === 'class') {
-      return attrValue.replace(/^(["'])?\s+/, '$1').replace(/\s+(["'])?$/, '$1');
+      // trim and collapse whitesapce
+      return attrValue.replace(/^(["'])?\s+/, '$1').replace(/\s+(["'])?$/, '$1').replace(/\s+/g, ' ');
     }
     return attrValue;
   }
index 5d2620e..1e75ad9 100644 (file)
@@ -95,6 +95,9 @@
           
           input = '<p class="\n  \n foo   \n\n\t  \t\n   ">foo bar baz</p>';
           equals(minify(input, { shouldCleanAttributes: true }), '<p class="foo">foo bar baz</p>');
+          
+          input = '<p class="\n  \n foo   \n\n\t  \t\n  class1 class-23 ">foo bar baz</p>';
+          equals(minify(input, { shouldCleanAttributes: true }), '<p class="foo class1 class-23">foo bar baz</p>');
         });
         
       })(this);