From 8be49c3ed10f8c728212df60b908bfab341c7683 Mon Sep 17 00:00:00 2001 From: Kristoffer Gram Date: Tue, 16 Jan 2018 19:15:21 +0100 Subject: [PATCH 1/3] Allow modules that resolve to falsy values in tests --- test/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 + "}"; }); From 5ed83f9a3c81819517aaf62073be0bfb8fde4673 Mon Sep 17 00:00:00 2001 From: Kristoffer Gram Date: Tue, 16 Jan 2018 19:15:58 +0100 Subject: [PATCH 2/3] Add tests for empty-object module and null module --- test/urlTest.js | 6 ++++++ 1 file changed, 6 insertions(+) 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 }", ""] From 127468d69b4e02d59c7e21ac20b22a86000f0568 Mon Sep 17 00:00:00 2001 From: Kristoffer Gram Date: Tue, 16 Jan 2018 19:16:26 +0100 Subject: [PATCH 3/3] Do not attempt escape of non-string dependencies --- lib/url/escape.js | 3 +++ 1 file changed, 3 insertions(+) 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);