Skip to content

Commit 4fcdd46

Browse files
author
evilebottnawi
committed
fix: skip handle empty url
1 parent 91e0316 commit 4fcdd46

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/urls.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ module.exports = function (css) {
6262
.replace(/^'(.*)'$/, function(o, $1){ return $1; });
6363

6464
// already a full url? no change
65-
if (/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/)/i.test(unquotedOrigUrl)) {
66-
return fullMatch;
67-
}
65+
if (/^(#|data:|http:\/\/|https:\/\/|file:\/\/\/|\s*$)/i.test(unquotedOrigUrl)) {
66+
return fullMatch;
67+
}
6868

6969
// convert the url to a full url
7070
var newUrl;

test/fixUrls.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ describe("fix urls tests", function() {
143143
assertUrl("body { background-image:url(#bg.jpg); }");
144144
});
145145

146+
// empty urls
147+
it("Empty url should be skipped", function() {
148+
assertUrl("body { background-image:url(); }");
149+
assertUrl("body { background-image:url( ); }");
150+
assertUrl("body { background-image:url(\n); }");
151+
assertUrl("body { background-image:url(''); }");
152+
assertUrl("body { background-image:url(' '); }");
153+
assertUrl("body { background-image:url(\"\"); }");
154+
assertUrl("body { background-image:url(\" \"); }");
155+
});
156+
146157
// rooted urls
147158
it("Rooted url", function() {
148159
assertUrl(

0 commit comments

Comments
 (0)