From 0b21fcefb38d1a37ddcdc4e35108e0ae0c22fdf4 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 15 Feb 2018 20:19:35 +0300 Subject: [PATCH] fix: skip handle empty url --- lib/urls.js | 2 +- test/fixUrls.test.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/urls.js b/lib/urls.js index d215ae84..a2259aba 100644 --- a/lib/urls.js +++ b/lib/urls.js @@ -62,7 +62,7 @@ module.exports = function (css) { .replace(/^'(.*)'$/, function(o, $1){ return $1; }); // already a full url? no change - if (/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/)/i.test(unquotedOrigUrl)) { + if (/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(unquotedOrigUrl)) { return fullMatch; } diff --git a/test/fixUrls.test.js b/test/fixUrls.test.js index d8d6ae57..3781eedf 100644 --- a/test/fixUrls.test.js +++ b/test/fixUrls.test.js @@ -143,6 +143,17 @@ describe("fix urls tests", function() { assertUrl("body { background-image:url(#bg.jpg); }"); }); + // empty urls + it("Empty url should be skipped", function() { + assertUrl("body { background-image:url(); }"); + assertUrl("body { background-image:url( ); }"); + assertUrl("body { background-image:url(\n); }"); + assertUrl("body { background-image:url(''); }"); + assertUrl("body { background-image:url(' '); }"); + assertUrl("body { background-image:url(\"\"); }"); + assertUrl("body { background-image:url(\" \"); }"); + }); + // rooted urls it("Rooted url", function() { assertUrl(