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: allow to specify a full hostname as root URL #521

Merged
merged 1 commit into from Apr 26, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/processCss.js
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
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