Skip to content

Commit 0f6cb90

Browse files
darrenscerrijhnns
authored andcommitted
fix: Empty urls are not rewritten to relative requests
Prior to this commit, `urlToRequest` rewrote an empty URL `''` to `'./'` which is correct from a theoretical point of view since CSS files do not distinguish between relative paths starting with ./ or not (like CommonJS does). However, an empty URL is most likely an error which webpack should warn about. If we rewrite the empty string to ./, webpack won't warn against this anymore because requiring ./ is valid. Related discussion: #80
1 parent 52fbc35 commit 0f6cb90

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/urlToRequest.js

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
const matchNativeWin32Path = /^[A-Z]:[/\\]|^\\\\/i;
55

66
function urlToRequest(url, root) {
7+
// Do not rewrite an empty url
8+
if(url === "") {
9+
return "";
10+
}
11+
712
const moduleRequestRegex = /^[^?]*~/;
813
let request;
914

test/urlToRequest.test.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ describe("urlToRequest()", () => {
3535
// error cases
3636
[["/path/to/thing", 1], new ExpectedError(/unexpected parameters/i), "should throw an error on invalid root"],
3737
// difficult cases
38-
[["a:b-not-\\window-path"], "./a:b-not-\\window-path", "should not incorrectly detect windows paths"]
38+
[["a:b-not-\\window-path"], "./a:b-not-\\window-path", "should not incorrectly detect windows paths"],
39+
// empty url
40+
[[""], "", "should do nothing if url is empty"]
3941
].forEach((test) => {
4042
it(test[2], () => {
4143
const expected = test[1];

0 commit comments

Comments
 (0)