Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/processCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,15 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
break;
case "url":
if (options.url && !/^#/.test(item.url) && loaderUtils.isUrlRequest(item.url, options.root)) {
item.stringType = "";
if (item.url.indexOf(" ") === -1) {
item.stringType = "";
}
delete item.innerSpacingBefore;
delete item.innerSpacingAfter;
var url = item.url;
item.url = "___CSS_LOADER_URL___" + urlItems.length + "___";
urlItems.push({
// Add quotes aroung url when contain space
url: url
});
}
Expand Down
2 changes: 2 additions & 0 deletions test/moduleTestCases/urls/expected.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
._a_ {
background: url({./module});
background: url({./module});
background: url("{./module module}");
background: url('{./module module}');
background: url({./module});
background: url({./module}#?iefix);
background: url("#hash");
Expand Down
2 changes: 2 additions & 0 deletions test/moduleTestCases/urls/source.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.a {
background: url(./module);
background: url("./module");
background: url("./module module");
background: url('./module module');
background: url('./module');
background: url("./module#?iefix");
background: url("#hash");
Expand Down
12 changes: 12 additions & 0 deletions test/urlTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ describe("url", function() {
test("background img 3", ".class { background: green url( 'img.png' ) xyz }", [
[1, ".class { background: green url({./img.png}) xyz }", ""]
]);
test("background img contain space in name", ".class { background: green url( \"img img.png\" ) xyz }", [
[1, ".class { background: green url(\"{./img img.png}\") xyz }", ""]
]);
test("background 2 img contain space in name", ".class { background: green url( 'img img.png' ) xyz }", [
[1, ".class { background: green url('{./img img.png}') xyz }", ""]
]);
test("background img absolute", ".class { background: green url(/img.png) xyz }", [
[1, ".class { background: green url(/img.png) xyz }", ""]
]);
Expand Down Expand Up @@ -63,6 +69,12 @@ describe("url", function() {
test("background img 3 with url", ".class { background: green url( 'img.png' ) xyz }", [
[1, ".class { background: green url( 'img.png' ) xyz }", ""]
], "?-url");
test("background img with url contain space in name", ".class { background: green url( \"img img.png\" ) xyz }", [
[1, ".class { background: green url( \"img img.png\" ) xyz }", ""]
], "?-url");
test("background 2 img with url contain space in name", ".class { background: green url( 'img img.png' ) xyz }", [
[1, ".class { background: green url( 'img img.png' ) xyz }", ""]
], "?-url");
test("background img absolute with url", ".class { background: green url(/img.png) xyz }", [
[1, ".class { background: green url(/img.png) xyz }", ""]
], "?-url");
Expand Down