Fixes #162 - strips quotes from base64 encoded URLs.
authorGoalSmashers <jakub@goalsmashers.com>
Sat, 2 Nov 2013 16:26:44 +0000 (17:26 +0100)
committerGoalSmashers <jakub@goalsmashers.com>
Sat, 2 Nov 2013 16:26:44 +0000 (17:26 +0100)
History.md
lib/clean.js
test/unit-test.js

index e1a3696..48441c5 100644 (file)
@@ -7,6 +7,7 @@
 * Adds missing `@import` processing to our benchmark (run via `npm run bench`).
 * Fixed issue [#157](https://github.com/GoalSmashers/clean-css/issues/157) - gets rid of `removeEmpty` option.
 * Fixed issue [#159](https://github.com/GoalSmashers/clean-css/issues/159) - escaped quotes inside content.
+* Fixed issue [#162](https://github.com/GoalSmashers/clean-css/issues/162) - strip quotes from base64 encoded URLs.
 
 1.1.7 / 2013-10-28
 ==================
index 7829137..105bad8 100644 (file)
@@ -85,7 +85,8 @@ var CleanCSS = {
 
     // strip parentheses in urls if possible (no spaces inside)
     replace(/url\((['"])([^\)]+)['"]\)/g, function(match, quote, url) {
-      if (url.match(/[ \t]/g) !== null || url.indexOf('data:') === 0)
+      var unsafeDataURI = url.indexOf('data:') === 0 && url.match(/data:\w+\/[^;]+;base64,/) === null;
+      if (url.match(/[ \t]/g) !== null || unsafeDataURI)
         return 'url(' + quote + url + quote + ')';
       else
         return 'url(' + url + ')';
index 513e568..17eb951 100644 (file)
@@ -619,7 +619,15 @@ vows.describe('clean-units').addBatch({
   }),
   'urls': cssContext({
     'keep urls without parentheses unchanged': 'a{background:url(/images/blank.png) 0 0 no-repeat}',
-    'keep urls with data URI unchanged': ".icon-logo{background-image:url('data:image/svg+xml;charset=US-ASCII')}",
+    'keep non-encoded data URI unchanged': ".icon-logo{background-image:url('data:image/svg+xml;charset=US-ASCII')}",
+    'strip quotes from base64 encoded PNG data URI': [
+      ".icon-logo{background-image:url('data:image/png;base64,iVBORw0')}",
+      ".icon-logo{background-image:url(data:image/png;base64,iVBORw0)}"
+    ],
+    'strip quotes from base64 encoded ICO data URI': [
+      '.icon-logo{background-image:url("data:image/x-icon;base64,AAABAAEAEBA")}',
+      '.icon-logo{background-image:url(data:image/x-icon;base64,AAABAAEAEBA)}'
+    ],
     'strip single parentheses': [
       "a{background:url('/images/blank.png') 0 0 no-repeat}",
       "a{background:url(/images/blank.png) 0 0 no-repeat}"