Skip to content

Commit

Permalink
Fixed: trim url first.
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Apr 26, 2017
1 parent a62bb30 commit 639bef1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions lib/processCss.js
Expand Up @@ -161,18 +161,18 @@ module.exports = function processCss(inputSource, inputMap, options, callback) {
var pipeline = postcss([
localByDefault({
mode: options.mode,
rewriteUrl: function(global, origUrl) {
rewriteUrl: function(global, url) {
if(parserOptions.url){
var url = origUrl.trim(" ");
url = url.trim();

if(!origUrl.replace(/\s/g, '').length || !loaderUtils.isUrlRequest(url, root)) {
return origUrl;
if(!url.replace(/\s/g, '').length || !loaderUtils.isUrlRequest(url, root)) {
return url;
}
if(global) {
return loaderUtils.urlToRequest(url, root);
}
}
return origUrl;
return url;
}
}),
extractImports(),
Expand Down
8 changes: 4 additions & 4 deletions test/urlTest.js
Expand Up @@ -77,16 +77,16 @@ describe("url", function() {
[1, ".class { background: green url('') xyz }", ""]
]);
test("empty url with spaces and quotes", ".class { background: green url(' ') xyz }", [
[1, ".class { background: green url(' ') xyz }", ""]
[1, ".class { background: green url('') xyz }", ""]
]);
test("empty url with newline and quotes", ".class { background: green url('\n') xyz }", [
[1, ".class { background: green url('\n') xyz }", ""]
[1, ".class { background: green url('') xyz }", ""]
]);
test("empty url with CRLF and quotes", ".class { background: green url('\r\n') xyz }", [
[1, ".class { background: green url('\r\n') xyz }", ""]
[1, ".class { background: green url('') xyz }", ""]
]);
test("empty url with tab and quotes", ".class { background: green url('\t') xyz }", [
[1, ".class { background: green url('\t') xyz }", ""]
[1, ".class { background: green url('') xyz }", ""]
]);
test("external absolute url", ".class { background: green url(https://raw.githubusercontent.com/webpack/media/master/logo/icon.png) xyz }", [
[1, ".class { background: green url(https://raw.githubusercontent.com/webpack/media/master/logo/icon.png) xyz }", ""]
Expand Down

0 comments on commit 639bef1

Please sign in to comment.