Fixes #611 - an edge case in quote stripping.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 24 Jun 2015 07:46:06 +0000 (08:46 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Wed, 24 Jun 2015 08:25:25 +0000 (09:25 +0100)
It manifested itself when rebasing to a relative or
absolute path only.

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

index 56f54f8..bd5cdb9 100644 (file)
@@ -3,6 +3,11 @@
 
 * Fixed issue [#599](https://github.com/jakubpawlowicz/clean-css/issues/599) - support for inlined source maps.
 
+[3.3.4 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.3.3...3.3)
+==================
+
+* Fixed issue [#611](https://github.com/jakubpawlowicz/clean-css/issues/611) - edge case in quote stripping.
+
 [3.3.3 / 2015-06-16](https://github.com/jakubpawlowicz/clean-css/compare/v3.3.2...v3.3.3)
 ==================
 
index 36db88e..26b30f2 100644 (file)
@@ -73,6 +73,8 @@ function quoteFor(url) {
     return '"';
   else if (url.indexOf('"') > -1)
     return '\'';
+  else if (/\s/.test(url))
+    return '\'';
   else
     return '';
 }
index 06b9867..53e78dd 100644 (file)
@@ -1259,6 +1259,14 @@ vows.describe('integration tests')
         'a{background:url("/images/blank.png")}',
         'a{background:url(/images/blank.png)}'
       ],
+      'keep quoting if whitespace': [
+        'a{background:url("/images/blank image.png")}',
+        'a{background:url("/images/blank image.png")}'
+      ],
+      'keep quoting if whitespace inside @font-face': [
+        '@font-face{src:url("Helvetica Neue.eot")}',
+        '@font-face{src:url("Helvetica Neue.eot")}'
+      ],
       'strip more': [
         'p{background:url("/images/blank.png")}b{display:block}a{background:url("/images/blank2.png")}',
         'p{background:url(/images/blank.png)}b{display:block}a{background:url(/images/blank2.png)}'
@@ -1309,6 +1317,26 @@ vows.describe('integration tests')
       ]
     }, { compatibility: 'ie8' })
   )
+  .addBatch(
+    optimizerContext('urls whitespace with url rewriting', {
+      'strip single parentheses': [
+        'a{background:url("/images/blank.png")}',
+        'a{background:url(/images/blank.png)}'
+      ],
+      'strip double parentheses': [
+        'a{background:url("/images/blank.png")}',
+        'a{background:url(/images/blank.png)}'
+      ],
+      'keep quoting if whitespace': [
+        'a{background:url("/images/blank image.png")}',
+        'a{background:url(\'/images/blank image.png\')}'
+      ],
+      'keep quoting if whitespace inside @font-face': [
+        '@font-face{src:url("/Helvetica Neue.eot")}',
+        '@font-face{src:url(\'/Helvetica Neue.eot\')}'
+      ]
+    }, { root: process.cwd(), relativeTo: process.cwd() })
+  )
   .addBatch(
     optimizerContext('urls quotes in compatibility mode', {
       'keeps quotes as they are': [