From a57f8abd1fea1d7f4f036793bc4adad2512fc6a7 Mon Sep 17 00:00:00 2001 From: Joel Gallant Date: Wed, 10 Oct 2018 09:05:01 -0600 Subject: [PATCH] Trims whitespace in import urls for unquoted imports Fixes #781 --- lib/loader.js | 6 +++++- test/importTest.js | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/loader.js b/lib/loader.js index b76c86de3..c31d5dead 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -49,7 +49,11 @@ module.exports = function(content, map) { var importUrlPrefix = getImportPrefix(this, query); var alreadyImported = {}; - var importJs = result.importItems.filter(function(imp) { + var importJs = result.importItems.map(function(imp) { + // fixes #781 when importing `url(filename.css )` + imp.url = imp.url.trim(); + return imp; + }).filter(function(imp) { if(!imp.mediaQuery) { if(alreadyImported[imp.url]) return false; diff --git a/test/importTest.js b/test/importTest.js index f3cdba580..3d8b9aa2c 100644 --- a/test/importTest.js +++ b/test/importTest.js @@ -13,6 +13,12 @@ describe("import", function() { ], "", { "./test.css": [[2, ".test{a: b}", ""]] }); + test("import", "@import url(test.css );\n.class { a: b c d; }", [ + [2, ".test{a: b}", ""], + [1, ".class { a: b c d; }", ""] + ], "", { + "./test.css": [[2, ".test{a: b}", ""]] + }); test("import camelcase", "@IMPORT url(test.css);\n.class { a: b c d; }", [ [2, ".test{a: b}", ""], [1, ".class { a: b c d; }", ""]