Fixes #357 - remaining non-standard but valid URL syntax.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 8 Jan 2015 23:22:48 +0000 (23:22 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Thu, 8 Jan 2015 23:23:55 +0000 (23:23 +0000)
History.md
lib/text/urls-processor.js
test/integration-test.js

index 35e42df..ca0c211 100644 (file)
@@ -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)
 ==================
index 4f23243..8b5bbfa 100644 (file)
@@ -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')
index 92be116..ea779bf 100644 (file)
@@ -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({