-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
doc: clarify url doc #19899
doc: clarify url doc #19899
Conversation
Indicate that `base` is ignored if `input` is absolute.
Please also indicate this is only the case if the Schemas of base and input are different. |
@wir3less ... what are you referring to when you say "Schemas"? I just went through and confirmed a number of cases: new URL('http://example.org', 'http://foo.com') // --> http://example.org
new URL('foo://bar', 'foo://baz') // --> foo://bar
new URL('foo://bar', 'http://foo.com') // --> foo://bar
new URL('http://foo.com', 'foo://bar') // --> http://foo.com
new URL('foo://bar', 'bar://foo') // --> foo://bar
new URL('foo:bar', 'bar:foo') // --> foo:bar In these cases, regardless of whether the protocol was "special" or the same, the base is ignored. |
doc/api/url.md
Outdated
@@ -100,6 +100,8 @@ return `true`. | |||
Creates a new `URL` object by parsing the `input` relative to the `base`. If | |||
`base` is passed as a string, it will be parsed equivalent to `new URL(base)`. | |||
|
|||
The `base` is ignored if the `input` is an absolute URL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Micro-nit: Remove the two instances of the as we do not prefix variable names with it generally. I see we do it in the immediately preceding paragraph so I'm fine if you want to ignore this comment, as at least it's consistent in the immediate vicinity. But if you wanted to remove them from that paragraph too, cool by me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with @Trott's comment fixed.
@jasnell this is what I mean, sorry I forgot Slashes play a role here as well: const { URL } = require('url');
console.log(new URL('http://xxx.com','https://google.com').href); // => http://xxx.com/
console.log(new URL('https://xxx.com','https://google.com').href); // =>https://xxx.com/
console.log(new URL('http:xxx.com','https://google.com').href); // => http://xxx.com/
console.log(new URL('https:xxx.com','https://google.com').href); // => https://google.com/xxx.com |
Ah yes, the I can add additional wording to the docs to illustrate this case but suggested wording would be helpful. |
Happy to see someone enjoy these as much as I do :) |
Yep, examples are good. The one thing we need to be careful of is the fact that the URL standard was written to support many edge cases, it would be quite difficult to adequately cover them all. Let's play with some wording on this particular case but keep that in mind in terms of how we do it. |
How about changing the function signature in the docs to be:
And adding the following after the first paragraph (before TypeError):
const { URL } = require('url');
var myURL = new URL('http://anotherExample.org/', 'https://example.org/');
// http://anotherexample.org/
myURL = new URL('https://anotherExample.org/', 'https://example.org/');
// https://anotherexample.org/
myURL = new URL('foo://anotherExample.org/', 'https://example.org/');
// foo://anotherExample.org/
myURL = new URL('http:anotherExample.org/', 'https://example.org/');
// http://anotherexample.org/
myURL = new URL('https:anotherExample.org/', 'https://example.org/');
// https://example.org/anotherExample.org/
myURL = new URL('foo:anotherExample.org/', 'https://example.org/');
// foo:anotherExample.org/ |
That's good but I don't think we even need to bring the "untrusted" data into it... the same bit about needing the check the origin applies regardless if there's any chance at all that the |
I'm willing to agree here, as long as we have the examples showing some edge cases, I believe developers will get the point. |
@wir3less ... how's it look now? |
Looks good @jasnell |
Landed in cf48d1d. |
Indicate that `base` is ignored if `input` is absolute. PR-URL: #19899 Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
Indicate that `base` is ignored if `input` is absolute. PR-URL: #19899 Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
Can someone share the status of this issue? |
@wir3less that is correct. I guess you wonder why the docs are not updated on the website? This will be included in 10.x and likely in the next 9.x. It might also be included in 8.x at some point. |
got you, thanks for the update! |
Indicate that `base` is ignored if `input` is absolute. PR-URL: nodejs#19899 Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
Indicate that
base
is ignored ifinput
is absolute.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes