-
Notifications
You must be signed in to change notification settings - Fork 30k
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: add url.resolve() method's behaviour #8991
Conversation
@addaleax Done :) |
@minervapanda As far as I can see, what you’ve updated is the PR title, not the commit message itself (you can see that listed here). Changing the commit message requires a bit of git magic, and if you don’t feel up for that, don’t worry – something like that can be performed by the person who’s merging the PR, so you shouldn’t feel obligated to do anything. But if you want to give it a try:
This may seem tricky (and it’s certainly complicated) – if you have any questions, don’t hesitate to ask! (* Depending on your OS/system setup the editor may vary; if you end up in vim and can’t work with that (which I definitely can’t 😄), it might help to enter |
doc/api/url.md
Outdated
|
||
```js | ||
url.resolve('https://foo.tld', 'bar') // 'https://foo.tld/bar' | ||
url.resolve('wss://foo.tld', 'bar') // 'wss://bar' |
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.
Nit: very very tiny, feel free to ignore it. Can you align the comment with the one above? Same for the following line.
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.
@lpinca Please keep mentioning even the tiniest of mistakes I do. I am a beginner,I am learning a lot in this process.
I am going to fix all that you said.
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.
While you are at it also add semicolons mostly for consistency with other code example in the doc.
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
doc/api/url.md
Outdated
@@ -235,6 +235,19 @@ url.resolve('http://example.com/', '/one') // 'http://example.com/one' | |||
url.resolve('http://example.com/one', '/two') // 'http://example.com/two' | |||
``` | |||
|
|||
Note that `url.resolve()` method depends on the protocol given in the `from` parameter. |
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.
Nit: Can you please split lines longer than 80 chars over multiple lines? Thanks!
Wow! @addaleax ,you explained so simply :) Thanks a lot for making Git so simple for me. I understood what I was doing. I got stuck in the last step , Everything worked until I ran git push --force-with-lease origin p1 which showed : |
@minervapanda oh, yeah, that’s a typo, I meant |
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.
I'm sorry to intervene here but I have minor suggested changes for this PR. Using "like" about the special case protocols make it sound vague although the list is very well defined.
Thanks for this update!
doc/api/url.md
Outdated
@@ -235,6 +235,19 @@ url.resolve('http://example.com/', '/one') // 'http://example.com/one' | |||
url.resolve('http://example.com/one', '/two') // 'http://example.com/two' | |||
``` | |||
|
|||
Note that `url.resolve()` method depends on the protocol given in the `from` parameter. | |||
Some protocols like `https`, `file`, `ftp`, `wss` and `gopher` have special cases. |
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.
The list of protocols that are treated as special cases is very precise and actually defined as this list (see const slashedProtocol
in lib/url.js
) :
http
https
ftp
gopher
file
So protocol wss
is not treated as a special case (as well as ftps
or any other). I would change the sentence for something like this:
Some protocols (
http
,https
,ftp
,gopher
andfile
) are treated as special cases. Every other (for instanceftps
orwss
) is treated differently whether its URL ends in a slash or not. Although, a uniform behaviour of the method is achieved when the URL ends with a slash.
(note that I moved the last sentence up here)
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.
Hi, Sure I am making the changes.
doc/api/url.md
Outdated
```js | ||
url.resolve('https://foo.tld', 'bar') // 'https://foo.tld/bar' | ||
url.resolve('wss://foo.tld', 'bar') // 'wss://bar' | ||
url.resolve('ftps://foo.tld', 'bar') // 'ftps://bar' |
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.
To follow on my previous comment, I think it would be neat to include an example with a trailing / in a URL. Like adding this example to your list:
url.resolve("ftps://foo.tld/", "bar"); // 'ftps://foo.tld/bar'
36120b2
to
7f93629
Compare
``` | ||
|
||
Some protocols (`http`, `https`, `ftp`, `gopher` and `file`) are treated as special cases. |
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.
Can you add a line break at column <= 80? This applies for all lines not only this one.
Thanks!
c133999
to
83c7a88
Compare
@addaleax when can this be merged to the master ? |
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.
Thanks for the bump! This looks good to me with @lpinca’s nit addressed, but that can also happen when merging the PR as far as I’m concerned.
I’ll land this later today if nobody beats me to it/there are no objections.
``` | ||
|
||
Some protocols (`http`, `https`, `ftp`, `gopher` and `file`) are treated as special cases. |
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.
What is special about them? The docs don't say.
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.
It has been explained explicitly with the help of examples how the usual behaviour might differ taking into the consideration the different protocols
``` | ||
|
||
Some protocols (`http`, `https`, `ftp`, `gopher` and `file`) are treated as special cases. | ||
Every other (for instance ftps or wss) is treated differently whether its 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.
What is different? The docs don't say.
url.resolve('ftps://foo.tld', 'bar'); // 'ftps://bar' | ||
``` | ||
|
||
Although, the uniform behaviour of the method is achieved when the URL ends with a slash. |
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.
What is the uniform behaviour?
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.
#8057 Please go through the issue that has been addressed here.
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.
Sorry, that isn't helpful - the point of the docs is to explain, and they aren't, so having me go read a node issue to understand a doc change is a bit backwards.
As is, this PR adds some extra examples and some lines of text that basically say "look carefully at the examples to see how this API works, paying particular attention to the protocol scheme, because it changes the behaviour". This is arguably an improvement over the existing doc, if @addaleax is happy with that, I've no objection.
However, it still doesn't document the API behaviour. If you have the interest, the existing docs could be improved even more. If not, I understand.
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.
This is arguably an improvement over the existing doc
Yeah, that’s what my approval of this PR is based upon. I don’t disagree with you that this still leaves room for improvement.
This PR doesn't document the behaviour, it adds examples, and leaves it up to the user to try to figure out what the behaviour is by reading the examples. Is it possible to actually describe in words what the behaviour is? |
``` | ||
|
||
Some protocols (`http`, `https`, `ftp`, `gopher` and `file`) are treated as special cases. | ||
Every other (for instance ftps or wss) is treated differently whether its URL | ||
ends in a slash or not. |
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.
I would suggest wording this a bit differently:
The specific result of resolving a URL depends on the protocol scheme. URL's
using protocol `http://` or `https://`, for instance, resolve differently than
URLs using protocol `wss:`, as illustrated in the example below:
ping @minervapanda |
There hasn't been any activity here. I'm closing this. Feel free to reopen (or ping a collaborator) if I closed this in error. |
Checklist
Affected core subsystem(s)
url
Description of change
url.resolve() behaviour depends on the protocol in the "from" parameter of the method.