From 80418fac5bf7ce6bfe98f75dcb4c6c3aeb185d0d Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Thu, 8 Jan 2015 23:22:48 +0000 Subject: [PATCH] Fixes #357 - remaining non-standard but valid URL syntax. --- History.md | 1 + lib/text/urls-processor.js | 9 ++++++++- test/integration-test.js | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/History.md b/History.md index 35e42df1..ca0c211c 100644 --- a/History.md +++ b/History.md @@ -5,6 +5,7 @@ * Adds better non-adjacent selector merging when body is the same. * Fixed issue [#158](https://github.com/GoalSmashers/clean-css/issues/158) - adds body-based selectors reduction. * Fixed issue [#182](https://github.com/GoalSmashers/clean-css/issues/182) - removing space after closing brace. +* Fixed issue [#357](https://github.com/GoalSmashers/clean-css/issues/357) - non-standard but valid URLs. [3.0.2 / 2015-01-04](https://github.com/jakubpawlowicz/clean-css/compare/v3.0.1...v3.0.2) ================== diff --git a/lib/text/urls-processor.js b/lib/text/urls-processor.js index 4f232430..8b5bbfae 100644 --- a/lib/text/urls-processor.js +++ b/lib/text/urls-processor.js @@ -1,6 +1,7 @@ var EscapeStore = require('./escape-store'); var URL_PREFIX = 'url('; +var UPPERCASE_URL_PREFIX = 'URL('; var URL_SUFFIX = ')'; var lineBreak = require('os').EOL; @@ -16,6 +17,7 @@ function UrlsProcessor(context, saveWaypoints, removeTrailingSpace) { // instead of regexps to speed up the process. UrlsProcessor.prototype.escape = function (data) { var nextStart = 0; + var nextStartUpperCase = 0; var nextEnd = 0; var cursor = 0; var tempData = []; @@ -26,9 +28,13 @@ UrlsProcessor.prototype.escape = function (data) { for (; nextEnd < data.length;) { nextStart = data.indexOf(URL_PREFIX, nextEnd); - if (nextStart == -1) + nextStartUpperCase = data.indexOf(UPPERCASE_URL_PREFIX, nextEnd); + if (nextStart == -1 && nextStartUpperCase == -1) break; + if (nextStart == -1 && nextStartUpperCase > -1) + nextStart = nextStartUpperCase; + if (data[nextStart + URL_PREFIX.length] == '"') nextEnd = data.indexOf('"', nextStart + URL_PREFIX.length + 1); else if (data[nextStart + URL_PREFIX.length] == '\'') @@ -76,6 +82,7 @@ UrlsProcessor.prototype.escape = function (data) { function normalize(url) { url = url + .replace(/^url/i, 'url') .replace(/\\?\n|\\?\r\n/g, '') .replace(/(\s{2,}|\s)/g, ' ') .replace(/^url\((['"])? /, 'url($1') diff --git a/test/integration-test.js b/test/integration-test.js index 92be1165..ea779bf1 100644 --- a/test/integration-test.js +++ b/test/integration-test.js @@ -947,6 +947,10 @@ path)}', 'a{background:url("/very/long/\ path")}', 'a{background:url(/very/long/path)}' + ], + 'uppercase': [ + 'a{background-image: URL("images/image.png");}', + 'a{background-image:url(images/image.png)}' ] }), 'urls whitespace in compatibility mode': cssContext({ -- 2.34.1