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 1 commit
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(/^[a-z][a-z0-9+\-.]*:\/\//.test(url)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This RegExp is very liberal. I would like to be more conservative here since there are only three reasonable variations here:

  • http://
  • https://
  • // (protocol agnostic)

I can't think of a use-case where other protocols are useful.

So could you change that RegExp to /^(https?:)?\/\//i?

// An absolute url stays
request = url;
} else if(/^\.\.?\//.test(url)) {
// A relative url stays
request = url;
Expand Down
1 change: 1 addition & 0 deletions test/urlToRequest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ExpectedError.prototype.matches = function(err) {
describe("urlToRequest()", () => {
[
// without root
[["https://google.com"], "https://google.com", "should handle absolute urls"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add the test cases for the other variations

[["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