Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore invalid URLs (url()) #663

Merged
merged 3 commits into from Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evilebottnawi: To allow for falsy modules such as { './module': null } to still be resolved.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kgram thanks for clafiry 👍

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