Skip to content

Commit

Permalink
fix: ignore invalid URLs (url()) (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgram authored and michael-ciniawsky committed Jan 17, 2018
1 parent 0fc46c7 commit d1d8221
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions 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);
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.js
Expand Up @@ -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 + "}";
});
Expand Down
6 changes: 6 additions & 0 deletions test/urlTest.js
Expand Up @@ -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 }", ""]
Expand Down

0 comments on commit d1d8221

Please sign in to comment.