Skip to content

Commit d1d8221

Browse files
kgrammichael-ciniawsky
authored andcommitted
fix: ignore invalid URLs (url()) (#663)
1 parent 0fc46c7 commit d1d8221

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

lib/url/escape.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
module.exports = function escape(url) {
2+
if (typeof url !== 'string') {
3+
return url
4+
}
25
// If url is already wrapped in quotes, remove them
36
if (/^['"].*['"]$/.test(url)) {
47
url = url.slice(1, -1);

test/helpers.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function getEvaluated(output, modules) {
1616
return require("../lib/url/escape");
1717
if(module.indexOf("-!/path/css-loader!") === 0)
1818
module = module.substr(19);
19-
if(modules && modules[module])
19+
if(modules && module in modules)
2020
return modules[module];
2121
return "{" + module + "}";
2222
});

test/urlTest.js

+6
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ describe("url", function() {
125125
test("module from url-loader", ".class { background: green url(module) xyz }", [
126126
[1, ".class { background: green url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA) xyz }", ""]
127127
], "", { './module': "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA" });
128+
test("module from null-loader (empty object from webpack)", ".class { background: green url(module) xyz }", [
129+
[1, ".class { background: green url([object Object]) xyz }", ""]
130+
], "", { './module': {} });
131+
test("module is null", ".class { background: green url(module) xyz }", [
132+
[1, ".class { background: green url(null) xyz }", ""]
133+
], "", { './module': null });
128134

129135
test("background img with url", ".class { background: green url( \"img.png\" ) xyz }", [
130136
[1, ".class { background: green url( \"img.png\" ) xyz }", ""]

0 commit comments

Comments
 (0)