Uh oh!
There was an error while loading. Please reload this page.
doc: clarify url doc - #19899
Conversation
Indicate that `base` is ignored if `input` is absolute.
wir3less
commented
Apr 9, 2018
Please also indicate this is only the case if the Schemas of base and input are different. |
jasnell
commented
Apr 9, 2018
@wir3less ... what are you referring to when you say "Schemas"? I just went through and confirmed a number of cases: newURL('http://example.org','http://foo.com')// --> http://example.orgnewURL('foo://bar','foo://baz')// --> foo://barnewURL('foo://bar','http://foo.com')// --> foo://barnewURL('http://foo.com','foo://bar')// --> http://foo.comnewURL('foo://bar','bar://foo')// --> foo://barnewURL('foo:bar','bar:foo')// --> foo:barIn these cases, regardless of whether the protocol was "special" or the same, the base is ignored. |
| 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.
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.
@jasnell this is what I mean, sorry I forgot Slashes play a role here as well: const{URL}=require('url');console.log(newURL('http://xxx.com','https://google.com').href);// => http://xxx.com/console.log(newURL('https://xxx.com','https://google.com').href);// =>https://xxx.com/console.log(newURL('http:xxx.com','https://google.com').href);// => http://xxx.com/console.log(newURL('https:xxx.com','https://google.com').href);// => https://google.com/xxx.com |
jasnell
commented
Apr 10, 2018
Ah yes, the I can add additional wording to the docs to illustrate this case but suggested wording would be helpful. |
wir3less
commented
Apr 10, 2018
Happy to see someone enjoy these as much as I do :) |
jasnell
commented
Apr 10, 2018
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');varmyURL=newURL('http://anotherExample.org/','https://example.org/');// http://anotherexample.org/myURL=newURL('https://anotherExample.org/','https://example.org/');// https://anotherexample.org/myURL=newURL('foo://anotherExample.org/','https://example.org/');// foo://anotherExample.org/myURL=newURL('http:anotherExample.org/','https://example.org/');// http://anotherexample.org/myURL=newURL('https:anotherExample.org/','https://example.org/');// https://example.org/anotherExample.org/myURL=newURL('foo:anotherExample.org/','https://example.org/');// foo:anotherExample.org/ |
jasnell
commented
Apr 10, 2018
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 |
wir3less
commented
Apr 11, 2018
I'm willing to agree here, as long as we have the examples showing some edge cases, I believe developers will get the point. |
jasnell
commented
Apr 14, 2018
@wir3less ... how's it look now? |
wir3less
commented
Apr 15, 2018
Looks good @jasnell |
lpinca
commented
Apr 16, 2018
Landed in cf48d1d. |
Indicate that `base` is ignored if `input` is absolute. PR-URL: #19899 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Indicate that `base` is ignored if `input` is absolute. PR-URL: #19899 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
wir3less
commented
Apr 23, 2018
Can someone share the status of this issue? |
BridgeAR
commented
Apr 23, 2018
@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. |
wir3less
commented
Apr 23, 2018
got you, thanks for the update! |
Indicate that `base` is ignored if `input` is absolute. PR-URL: nodejs#19899 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Indicate that
baseis ignored ifinputis absolute.Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes