diff --git a/lib/url/escape.js b/lib/url/escape.js index be9bd2c8..25074a6e 100644 --- a/lib/url/escape.js +++ b/lib/url/escape.js @@ -1,4 +1,7 @@ module.exports = function escape(url) { + if (typeof url !== 'string') { + return url + } // If url is already wrapped in quotes, remove them if (/^['"].*['"]$/.test(url)) { url = url.slice(1, -1); diff --git a/test/helpers.js b/test/helpers.js index df0d14b6..5764527a 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -16,7 +16,7 @@ function getEvaluated(output, modules) { return require("../lib/url/escape"); if(module.indexOf("-!/path/css-loader!") === 0) module = module.substr(19); - if(modules && modules[module]) + if(modules && module in modules) return modules[module]; return "{" + module + "}"; }); diff --git a/test/urlTest.js b/test/urlTest.js index 4690319c..543a47fe 100644 --- a/test/urlTest.js +++ b/test/urlTest.js @@ -125,6 +125,12 @@ describe("url", function() { test("module from url-loader", ".class { background: green url(module) xyz }", [ [1, ".class { background: green url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA) xyz }", ""] ], "", { './module': "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA" }); + test("module from null-loader (empty object from webpack)", ".class { background: green url(module) xyz }", [ + [1, ".class { background: green url([object Object]) xyz }", ""] + ], "", { './module': {} }); + test("module is null", ".class { background: green url(module) xyz }", [ + [1, ".class { background: green url(null) xyz }", ""] + ], "", { './module': null }); test("background img with url", ".class { background: green url( \"img.png\" ) xyz }", [ [1, ".class { background: green url( \"img.png\" ) xyz }", ""]