Fixes #217 - removing extra whitespace from attribute selectors and urls.
authorGoalSmashers <jakub@goalsmashers.com>
Sat, 1 Feb 2014 08:12:53 +0000 (08:12 +0000)
committerGoalSmashers <jakub@goalsmashers.com>
Sat, 1 Feb 2014 08:12:53 +0000 (08:12 +0000)
Browsers strip the whitespace before evaluating so should we.

History.md
lib/clean.js
lib/text/urls.js
test/unit-test.js

index d6ed550..daf1157 100644 (file)
@@ -13,6 +13,7 @@
 * Fixed issue [#186](https://github.com/GoalSmashers/clean-css/issues/186) - strip unit from 0rem.
 * Fixed issue [#207](https://github.com/GoalSmashers/clean-css/issues/207) - bug in parsing protocol `@import`s.
 * Fixed issue [#213](https://github.com/GoalSmashers/clean-css/issues/213) - faster rgb to hex transforms.
+* Fixed issue [#217](https://github.com/GoalSmashers/clean-css/issues/217) - whitespace inside attribute selectors and urls.
 * Fixed issue [#218](https://github.com/GoalSmashers/clean-css/issues/218) - `@import` statements cleanup.
 * Fixed issue [#220](https://github.com/GoalSmashers/clean-css/issues/220) - selector between comments.
 
index e0670b0..16ea17c 100644 (file)
@@ -194,6 +194,11 @@ var minify = function(data, callback) {
     data = urlsProcessor.escape(data);
   });
 
+  // whitespace inside attribute selectors brackets
+  replace(/\[([^\]]+)\]/g, function(match) {
+    return match.replace(/\s/g, '');
+  });
+
   // line breaks
   replace(/[\r]?\n/g, ' ');
 
index 8f7fee8..3e04c4b 100644 (file)
@@ -33,7 +33,9 @@ module.exports = function Urls() {
     },
 
     restore: function(data) {
-      return data.replace(urls.placeholderRegExp, urls.restore);
+      return data.replace(urls.placeholderRegExp, function(placeholder) {
+        return urls.restore(placeholder).replace(/\s/g, '');
+      });
     }
   };
 };
index 165ed28..bf4c423 100644 (file)
@@ -918,6 +918,14 @@ title']{display:block}",
       ".test[title='my_very_long_\
 title']{display:block}",
       ".test[title=my_very_long_title]{display:block}"
+    ],
+    'should strip whitespace between square brackets': [
+      'body[  data-title ]{color:red}',
+      'body[data-title]{color:red}'
+    ],
+    'should strip whitespace inside square brackets': [
+      'body[  data-title  = x ]{color:red}',
+      'body[data-title=x]{color:red}'
     ]
   }),
   'ie filters': cssContext({
@@ -1172,6 +1180,10 @@ title']{display:block}",
     'of an unknown file': [
       "@import url(/fake.css);",
       "@import url(/fake.css);"
+    ],
+    'of an unknown file with extra whitespace': [
+      "@import url(  /fake.css );",
+      "@import url(/fake.css);"
     ]
   }, { processImport: false }),
   'duplicate selectors with disabled advanced processing': cssContext({