From 06d27a15652ecc15a6ea1029a1e142ab2f9bcfe0 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Wed, 26 Apr 2017 22:32:18 +0300 Subject: [PATCH] fix: allow to specify a full hostname as a root URL (#521) --- lib/processCss.js | 2 +- test/urlTest.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/processCss.js b/lib/processCss.js index 34017d5e..6dcb909a 100644 --- a/lib/processCss.js +++ b/lib/processCss.js @@ -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; diff --git a/test/urlTest.js b/test/urlTest.js index e25a4b77..5f5b7f52 100644 --- a/test/urlTest.js +++ b/test/urlTest.js @@ -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 }", ""]