-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
url.resolve() behaves differently depending on the protocol of the base url #8921
Comments
Some protocols (http, https, file, ftp and, yes, gopher) are treated specially, to match browser behavior ca. 2010, when the url module was introduced. I think it's confusing but it's probably hard to change because of backwards compatibility. It's more likely to simply be subsumed by WHATWG URL support, ref #7448. EDIT: Forgot to mention, if the URLs end in a slash, you get uniform behavior. I'll add documentation tags. |
Thanks @bnoordhuis. I believe that the information you give in your comment (the list of protocols which are treated specially and the uniform behavior when the URL ends with a slash) definitely has its place in the documentation. |
Assigned to myself as placeholder for @minervapanda |
According to my knowledge , the issue is pointing to the url.md to the following lines of url.resolve() : url.resolve('/one/two/three', 'four') // '/one/two/four' It looks good to me. Please correct me if I am wrong. |
@minervapanda Yes, the issue is pointing to these lines and the examples are correct. However, the documentation does not tell that:
|
Thank you for the clarification @rolinh . I was confused ,the example seemed correct.I will make a PR to update the documentation.Thanks. |
I'm optimizing the new version of Chrome's settings UI written in Polymer. The node-based tool I was using (vulcanize) calls I tracked it back to unexpected results with > require('url').resolve('chrome://settings', '/page.html')
chrome:///page.html For what it's worth, I also messed around with adding a slash at the end of the > require('url').resolve('chrome://settings/', '/page.html')
chrome:///page.html I expected When i change the protocol, I get more expected results: > require('url').resolve('http://chrome.tld', '/blah.html')
http://chrome.tld/blah.html I assume this has to do with the whitelist of protocols in lib/url.js. Certainly things could be added to this list, but the returns are diminishing. I also found this todo: // v0.12 TODO(isaacs): This is not quite how Chrome does things. This got me thinking: is node interested in using an implementation from an open source browser like /cc @arv as an FYI |
The current direction is to leave the existing |
@danbeam, indeed, in Node.js v7 you can already do: const { URL } = require('url');
console.log(new URL('/page.html', 'chrome://settings/').href);
// Prints 'chrome://settings/page.html' Or if Node.js v7 is too high of a requirement, @domenic's whatwg-url would also work. |
This issue has been inactive for sufficiently long that it seems like perhaps it should be closed. Feel free to re-open (or leave a comment requesting that it be re-opened) if you disagree. I'm just tidying up and not acting on a super-strong opinion or anything like that. |
The
url.resolve()
function behaves differently depending on the protocol given in thefrom
parameter.See this example:
When reading this function's documentation, this is not a behavior that I could foresee. I would have expected
'wss://foo.tld/bar'
and'ftps://foo.tld/bar'
as results of the last two calls respectively.The text was updated successfully, but these errors were encountered: