Skip to content

Commit fface50

Browse files
japgollyjhnns
authored andcommitted
fix: Do not rewrite actual URLs that start with http://, https:// or just //
Prior to this commit, an actual URL starting with a protocol like`https://` would have been rewritten to `./https://` which is clearly undesired. Although webpack can't resolve remote module requests anyway (those starting with http:// and such) and thus will throw an error, it is still correct to leave these kind of URLs untouched by the loader-utils. Related discussion: #79
1 parent 0f6cb90 commit fface50

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/urlToRequest.js

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ function urlToRequest(url, root) {
3535
default:
3636
throw new Error("Unexpected parameters to loader-utils 'urlToRequest': url = " + url + ", root = " + root + ".");
3737
}
38+
} else if(/^(?:https?:)?\/\//.test(url)) {
39+
// Preserve http and https urls
40+
request = url;
3841
} else if(/^\.\.?\//.test(url)) {
3942
// A relative url stays
4043
request = url;

test/urlToRequest.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ ExpectedError.prototype.matches = function(err) {
1313
describe("urlToRequest()", () => {
1414
[
1515
// without root
16+
[["//google.com"], "//google.com", "should handle scheme-agnostic urls"],
17+
[["http://google.com"], "http://google.com", "should handle http urls"],
18+
[["https://google.com"], "https://google.com", "should handle https urls"],
1619
[["path/to/thing"], "./path/to/thing", "should handle implicit relative urls"],
1720
[["./path/to/thing"], "./path/to/thing", "should handle explicit relative urls"],
1821
[["~path/to/thing"], "path/to/thing", "should handle module urls (with ~)"],

0 commit comments

Comments
 (0)