From: GoalSmashers Date: Sat, 1 Feb 2014 08:12:53 +0000 (+0000) Subject: Fixes #217 - removing extra whitespace from attribute selectors and urls. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=9a826083fe06041becba04d8f52af26cb9f04b8c;p=clean-css.git Fixes #217 - removing extra whitespace from attribute selectors and urls. Browsers strip the whitespace before evaluating so should we. --- diff --git a/History.md b/History.md index d6ed550c..daf11571 100644 --- a/History.md +++ b/History.md @@ -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. diff --git a/lib/clean.js b/lib/clean.js index e0670b04..16ea17c4 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -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, ' '); diff --git a/lib/text/urls.js b/lib/text/urls.js index 8f7fee8b..3e04c4b0 100644 --- a/lib/text/urls.js +++ b/lib/text/urls.js @@ -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, ''); + }); } }; }; diff --git a/test/unit-test.js b/test/unit-test.js index 165ed28d..bf4c4237 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -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({