Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle absolute URLs in urlToRequest #79

Merged
merged 2 commits into from
Mar 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/urlToRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,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