From: GoalSmashers Date: Sat, 2 Nov 2013 16:26:44 +0000 (+0100) Subject: Fixes #162 - strips quotes from base64 encoded URLs. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=1d9ee509bb49150c1f4d410c782eb700aac378f0;p=clean-css.git Fixes #162 - strips quotes from base64 encoded URLs. --- diff --git a/History.md b/History.md index e1a36964..48441c51 100644 --- a/History.md +++ b/History.md @@ -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 ================== diff --git a/lib/clean.js b/lib/clean.js index 78291376..105bad83 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -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 + ')'; diff --git a/test/unit-test.js b/test/unit-test.js index 513e568a..17eb951e 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -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}"