From 9124835d3aa4ded91caf7a939b5202f4977bdcac Mon Sep 17 00:00:00 2001 From: David Barri Date: Wed, 22 Mar 2017 17:38:53 +1100 Subject: [PATCH 1/2] Handle absolute URLs in urlToRequest --- lib/urlToRequest.js | 3 +++ test/urlToRequest.test.js | 1 + 2 files changed, 4 insertions(+) diff --git a/lib/urlToRequest.js b/lib/urlToRequest.js index 06c3cd0..45d0e2b 100644 --- a/lib/urlToRequest.js +++ b/lib/urlToRequest.js @@ -30,6 +30,9 @@ function urlToRequest(url, root) { default: throw new Error("Unexpected parameters to loader-utils 'urlToRequest': url = " + url + ", root = " + root + "."); } + } else if(/^[a-z][a-z0-9+\-.]*:\/\//.test(url)) { + // An absolute url stays + 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 6fa0a0e..a27a157 100644 --- a/test/urlToRequest.test.js +++ b/test/urlToRequest.test.js @@ -13,6 +13,7 @@ ExpectedError.prototype.matches = function(err) { describe("urlToRequest()", () => { [ // without root + [["https://google.com"], "https://google.com", "should handle absolute 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 ~)"], From fc57e990c03b13984e4f8b14753c61938bb1a391 Mon Sep 17 00:00:00 2001 From: David Barri Date: Fri, 24 Mar 2017 13:35:32 +1100 Subject: [PATCH 2/2] PR feedback: support http, https, and // --- lib/urlToRequest.js | 4 ++-- test/urlToRequest.test.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/urlToRequest.js b/lib/urlToRequest.js index 45d0e2b..ebdce9c 100644 --- a/lib/urlToRequest.js +++ b/lib/urlToRequest.js @@ -30,8 +30,8 @@ function urlToRequest(url, root) { default: throw new Error("Unexpected parameters to loader-utils 'urlToRequest': url = " + url + ", root = " + root + "."); } - } else if(/^[a-z][a-z0-9+\-.]*:\/\//.test(url)) { - // An absolute url stays + } else if(/^(?:https?:)?\/\//.test(url)) { + // Preserve http and https urls request = url; } else if(/^\.\.?\//.test(url)) { // A relative url stays diff --git a/test/urlToRequest.test.js b/test/urlToRequest.test.js index a27a157..5c53cad 100644 --- a/test/urlToRequest.test.js +++ b/test/urlToRequest.test.js @@ -13,7 +13,9 @@ ExpectedError.prototype.matches = function(err) { describe("urlToRequest()", () => { [ // without root - [["https://google.com"], "https://google.com", "should handle absolute urls"], + [["//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 ~)"],