Skip to content

Commit

Permalink
fix: allow to specify a full hostname as a root URL (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored and michael-ciniawsky committed Apr 26, 2017
1 parent b8f5c8f commit 06d27a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/processCss.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ var parserPlugin = postcss.plugin("css-loader-parser", function(options) {

module.exports = function processCss(inputSource, inputMap, options, callback) {
var query = options.query;
var root = query.root;
var root = query.root && query.root.length > 0 ? query.root.replace(/\/$/, "") : query.root;
var context = query.context;
var localIdentName = query.localIdentName || "[hash:base64]";
var localIdentRegExp = query.localIdentRegExp;
Expand Down
9 changes: 9 additions & 0 deletions test/urlTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ describe("url", function() {
test("background img absolute with root", ".class { background: green url(/img.png) xyz }", [
[1, ".class { background: green url({./img.png}) xyz }", ""]
], "?root=.");
test("background img absolute with root", ".class { background: green url(/img.png) xyz }", [
[1, ".class { background: green url({./img.png}) xyz }", ""]
], "?root=./");
test("root with absolute url", ".class { background: green url(/img.png) xyz }", [
[1, ".class { background: green url(http://some.cdn.com/img.png) xyz }", ""]
], "?root=http://some.cdn.com");
test("root with absolute url with trailing slash", ".class { background: green url(/img.png) xyz }", [
[1, ".class { background: green url(http://some.cdn.com/img.png) xyz }", ""]
], "?root=http://some.cdn.com/");
test("background img external",
".class { background: green url(data:image/png;base64,AAA) url(http://example.com/image.jpg) url(//example.com/image.png) xyz }", [
[1, ".class { background: green url(data:image/png;base64,AAA) url(http://example.com/image.jpg) url(//example.com/image.png) xyz }", ""]
Expand Down

0 comments on commit 06d27a1

Please sign in to comment.