Skip to content

Commit

Permalink
fix: Do not rewrite actual URLs that start with http://, https:// or …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
japgolly authored and jhnns committed Mar 24, 2017
1 parent 0f6cb90 commit fface50
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/urlToRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ function urlToRequest(url, root) {
default:
throw new Error("Unexpected parameters to loader-utils 'urlToRequest': url = " + url + ", root = " + root + ".");
}
} else if(/^(?:https?:)?\/\//.test(url)) {
// Preserve http and https urls
request = url;
} else if(/^\.\.?\//.test(url)) {
// A relative url stays
request = url;
Expand Down
3 changes: 3 additions & 0 deletions test/urlToRequest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ ExpectedError.prototype.matches = function(err) {
describe("urlToRequest()", () => {
[
// without root
[["//google.com"], "//google.com", "should handle scheme-agnostic urls"],
[["http://google.com"], "http://google.com", "should handle http urls"],
[["https://google.com"], "https://google.com", "should handle https urls"],
[["path/to/thing"], "./path/to/thing", "should handle implicit relative urls"],
[["./path/to/thing"], "./path/to/thing", "should handle explicit relative urls"],
[["~path/to/thing"], "path/to/thing", "should handle module urls (with ~)"],
Expand Down

0 comments on commit fface50

Please sign in to comment.