Skip to content

Commit 06d27a1

Browse files
evilebottnawimichael-ciniawsky
authored andcommitted
fix: allow to specify a full hostname as a root URL (#521)
1 parent b8f5c8f commit 06d27a1

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/processCss.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {
139139

140140
module.exports = function processCss(inputSource, inputMap, options, callback) {
141141
var query = options.query;
142-
var root = query.root;
142+
var root = query.root && query.root.length > 0 ? query.root.replace(/\/$/, "") : query.root;
143143
var context = query.context;
144144
var localIdentName = query.localIdentName || "[hash:base64]";
145145
var localIdentRegExp = query.localIdentRegExp;

test/urlTest.js

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ describe("url", function() {
2727
test("background img absolute with root", ".class { background: green url(/img.png) xyz }", [
2828
[1, ".class { background: green url({./img.png}) xyz }", ""]
2929
], "?root=.");
30+
test("background img absolute with root", ".class { background: green url(/img.png) xyz }", [
31+
[1, ".class { background: green url({./img.png}) xyz }", ""]
32+
], "?root=./");
33+
test("root with absolute url", ".class { background: green url(/img.png) xyz }", [
34+
[1, ".class { background: green url(http://some.cdn.com/img.png) xyz }", ""]
35+
], "?root=http://some.cdn.com");
36+
test("root with absolute url with trailing slash", ".class { background: green url(/img.png) xyz }", [
37+
[1, ".class { background: green url(http://some.cdn.com/img.png) xyz }", ""]
38+
], "?root=http://some.cdn.com/");
3039
test("background img external",
3140
".class { background: green url(data:image/png;base64,AAA) url(http://example.com/image.jpg) url(//example.com/image.png) xyz }", [
3241
[1, ".class { background: green url(data:image/png;base64,AAA) url(http://example.com/image.jpg) url(//example.com/image.png) xyz }", ""]

0 commit comments

Comments
 (0)