Skip to content

Commit

Permalink
Fixed: loader now correctly handles url with space(s) [410].
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Apr 17, 2017
1 parent 2ee7552 commit 2e8a3e2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
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

0 comments on commit 2e8a3e2

Please sign in to comment.