Fixes #583 - URL quoting for SVG data.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 27 May 2015 08:19:48 +0000 (09:19 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 27 May 2015 08:19:48 +0000 (09:19 +0100)
If a SVG content is used directly in data: URI we need to make sure
correct quotes are used.

It works for any kind of URL however using quotes in the middle of URLs
is quite rare.

History.md
lib/urls/rewrite.js
test/integration-test.js

index bf67f5c..91b25e3 100644 (file)
@@ -19,6 +19,7 @@
 * Fixed issue [#575](https://github.com/jakubpawlowicz/clean-css/issues/575) - missing directory as a `target`.
 * Fixed issue [#577](https://github.com/jakubpawlowicz/clean-css/issues/577) - `background-clip` into shorthand.
 * Fixed issue [#579](https://github.com/jakubpawlowicz/clean-css/issues/579) - `background-origin` into shorthand.
+* Fixed issue [#583](https://github.com/jakubpawlowicz/clean-css/issues/583) - URL quoting for SVG data.
 
 [3.2.10 / 2015-05-14](https://github.com/jakubpawlowicz/clean-css/compare/v3.2.9...v3.2.10)
 ==================
index ef25130..36db88e 100644 (file)
@@ -68,10 +68,19 @@ function rebase(uri, options) {
     normalize(relative(uri, options));
 }
 
+function quoteFor(url) {
+  if (url.indexOf('\'') > -1)
+    return '"';
+  else if (url.indexOf('"') > -1)
+    return '\'';
+  else
+    return '';
+}
+
 function rewriteUrls(data, options, context) {
   return reduceUrls(data, context, function (url, tempData) {
     url = url.replace(/^(url\()?\s*['"]?|['"]?\s*\)?$/g, '');
-    tempData.push('url(' + rebase(url, options) + ')');
+    tempData.push('url(' + quoteFor(url) + rebase(url, options) + quoteFor(url) + ')');
   });
 }
 
index 435bd56..576b4b9 100644 (file)
@@ -1081,6 +1081,10 @@ path")}',
       '@import url(/test/fixtures/partials-relative/base.css);',
       'a{background:url(/test/fixtures/partials/extra/down.gif) no-repeat}'
     ],
+    'SVG': [
+      "a{background-image:url(\"data:image/svg+xml,<svg version='1.1'/>\")}",
+      "a{background-image:url(\"data:image/svg+xml,<svg version='1.1'/>\")}"
+    ],
     'document-local reference': [
       'svg{marker-end:url(#arrow)}',
       'svg{marker-end:url(#arrow)}'