Skip to content

Commit

Permalink
fix: loader now correctly handles url with space(s) (#495)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored and michael-ciniawsky committed Apr 17, 2017
1 parent 2ee7552 commit 534ea55
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
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
@@ -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
@@ -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
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 534ea55

Please sign in to comment.