Skip to content

Commit

Permalink
PR feedback: support http, https, and //
Browse files Browse the repository at this point in the history
  • Loading branch information
japgolly committed Mar 24, 2017
1 parent 9124835 commit fc57e99
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/urlToRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion test/urlToRequest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
[["https://google.com"], "https://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 fc57e99

Please sign in to comment.