Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: loader now correctly handles url with space(s) [#410]. #495

Merged
merged 1 commit into from
Apr 17, 2017
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