From fface504183c0e29e7701bbc4ab37447a726693a Mon Sep 17 00:00:00 2001 From: David Barri Date: Fri, 24 Mar 2017 23:41:08 +1100 Subject: [PATCH] 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: https://github.com/webpack/loader-utils/pull/79 --- lib/urlToRequest.js | 3 +++ test/urlToRequest.test.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/urlToRequest.js b/lib/urlToRequest.js index 285d14c..3ea6a0b 100644 --- a/lib/urlToRequest.js +++ b/lib/urlToRequest.js @@ -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; diff --git a/test/urlToRequest.test.js b/test/urlToRequest.test.js index 5d26654..40b5794 100644 --- a/test/urlToRequest.test.js +++ b/test/urlToRequest.test.js @@ -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 ~)"],