From 0d00d14c4235e58588b37a2c7aa298112fbf142f Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Thu, 12 Nov 2015 22:17:20 +0000 Subject: [PATCH] Fixes #676 - fuzzy matching in unquoted data URIs. 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 | 5 +++++ lib/urls/reduce.js | 8 ++++---- test/integration-test.js | 8 ++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/History.md b/History.md index 87cadc32..e6c9fdcd 100644 --- a/History.md +++ b/History.md @@ -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) ================== diff --git a/lib/urls/reduce.js b/lib/urls/reduce.js index cc4fb4a3..54c4ee7a 100644 --- a/lib/urls/reduce.js +++ b/lib/urls/reduce.js @@ -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; diff --git a/test/integration-test.js b/test/integration-test.js index ed02c422..9de944dc 100644 --- a/test/integration-test.js +++ b/test/integration-test.js @@ -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(), -- 2.34.1