Skip to content

Commit 534ea55

Browse files
evilebottnawimichael-ciniawsky
authored andcommittedApr 17, 2017
fix: loader now correctly handles url with space(s) (#495)
1 parent 2ee7552 commit 534ea55

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed
 

‎lib/processCss.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,15 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
9898
break;
9999
case "url":
100100
if (options.url && !/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) {
101-
item.stringType = "";
101+
if (item.url.indexOf(" ") === -1) {
102+
item.stringType = "";
103+
}
102104
delete item.innerSpacingBefore;
103105
delete item.innerSpacingAfter;
104106
var url = item.url;
105107
item.url = "___CSS_LOADER_URL___" + urlItems.length + "___";
106108
urlItems.push({
109+
// Add quotes aroung url when contain space
107110
url: url
108111
});
109112
}

‎test/moduleTestCases/urls/expected.css

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
._a_ {
22
background: url({./module});
33
background: url({./module});
4+
background: url("{./module module}");
5+
background: url('{./module module}');
46
background: url({./module});
57
background: url({./module}#?iefix);
68
background: url("#hash");

‎test/moduleTestCases/urls/source.css

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.a {
22
background: url(./module);
33
background: url("./module");
4+
background: url("./module module");
5+
background: url('./module module');
46
background: url('./module');
57
background: url("./module#?iefix");
68
background: url("#hash");

‎test/urlTest.js

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ describe("url", function() {
1212
test("background img 3", ".class { background: green url( 'img.png' ) xyz }", [
1313
[1, ".class { background: green url({./img.png}) xyz }", ""]
1414
]);
15+
test("background img contain space in name", ".class { background: green url( \"img img.png\" ) xyz }", [
16+
[1, ".class { background: green url(\"{./img img.png}\") xyz }", ""]
17+
]);
18+
test("background 2 img contain space in name", ".class { background: green url( 'img img.png' ) xyz }", [
19+
[1, ".class { background: green url('{./img img.png}') xyz }", ""]
20+
]);
1521
test("background img absolute", ".class { background: green url(/img.png) xyz }", [
1622
[1, ".class { background: green url(/img.png) xyz }", ""]
1723
]);
@@ -63,6 +69,12 @@ describe("url", function() {
6369
test("background img 3 with url", ".class { background: green url( 'img.png' ) xyz }", [
6470
[1, ".class { background: green url( 'img.png' ) xyz }", ""]
6571
], "?-url");
72+
test("background img with url contain space in name", ".class { background: green url( \"img img.png\" ) xyz }", [
73+
[1, ".class { background: green url( \"img img.png\" ) xyz }", ""]
74+
], "?-url");
75+
test("background 2 img with url contain space in name", ".class { background: green url( 'img img.png' ) xyz }", [
76+
[1, ".class { background: green url( 'img img.png' ) xyz }", ""]
77+
], "?-url");
6678
test("background img absolute with url", ".class { background: green url(/img.png) xyz }", [
6779
[1, ".class { background: green url(/img.png) xyz }", ""]
6880
], "?-url");

0 commit comments

Comments
 (0)