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 }", ""]