Fixes #676 - fuzzy matching in unquoted data URIs.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 12 Nov 2015 22:17:20 +0000 (22:17 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Fri, 13 Nov 2015 12:06:42 +0000 (12:06 +0000)
Instead of matching just whitespace, also curly braces and semicolons
needs to be fuzzy matched as those tokens indicate context beyond
escaped URI.

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

index 87cadc3..e6c9fdc 100644 (file)
@@ -3,6 +3,11 @@
 
 * Requires Node.js 4.0+ to run.
 
+[3.4.8 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.7...3.4)
+==================
+
+* Fixed issue [#676](https://github.com/jakubpawlowicz/clean-css/issues/676) - fuzzy matching unqoted data URIs.
+
 [3.4.7 / 2015-11-10](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.6...v3.4.7)
 ==================
 
index cc4fb4a..54c4ee7 100644 (file)
@@ -40,10 +40,10 @@ function byUrl(data, context, callback) {
         // this is a fuzzy matching logic for unqoted data URIs
         while (true) {
           nextEndAhead = data.indexOf(URL_SUFFIX, nextEnd + 1);
-          // if it has whitespace then we should be out of URL, otherwise keep iterating
-          // if it has not but content is not escaped, it has to be quoted so it will be captured
-          // by either of two clauses above
-          if (nextEndAhead == -1 || /\s/.test(data.substring(nextEnd, nextEndAhead)))
+          // if it has whitespace, curly braces, or semicolon then we should be out of URL,
+          // otherwise keep iterating if it has not but content is not escaped,
+          // it has to be quoted so it will be captured by either of two clauses above
+          if (nextEndAhead == -1 || /[\s\{\};]/.test(data.substring(nextEnd, nextEndAhead)))
             break;
 
           nextEnd = nextEndAhead;
index ed02c42..9de944d 100644 (file)
@@ -1492,6 +1492,14 @@ vows.describe('integration tests')
       'document-local reference': [
         'svg{marker-end:url(#arrow)}',
         'svg{marker-end:url(#arrow)}'
+      ],
+      'quoting URLs #1': [
+        'div{background:url("data:image/svg+xml;base64,==")}li:nth-child(odd){color:red}',
+        'div{background:url(data:image/svg+xml;base64,==)}li:nth-child(odd){color:red}'
+      ],
+      'quoting URLs #2': [
+        'div{background:url("data:image/svg+xml;base64,==");border-image:url(1.png)}li:nth-child(odd){color:red}',
+        'div{background:url(data:image/svg+xml;base64,==);border-image:url(test/fixtures/partials-relative/1.png)}li:nth-child(odd){color:red}'
       ]
     }, {
       target: process.cwd(),