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

doc: add url.resolve() method's behaviour #8991

Closed
wants to merge 1 commit into from

Conversation

minervapanda
Copy link

Checklist
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

url

Description of change

url.resolve() behaviour depends on the protocol in the "from" parameter of the method.

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. url Issues and PRs related to the legacy built-in url module. labels Oct 9, 2016
@addaleax
Copy link
Member

addaleax commented Oct 9, 2016

For the record, this continues from #8969 with sign-offs from me, @jasnell and @lpinca for the commit that is here, and a request to use add in the commit message.

Also, this fixes #8921.

@minervapanda minervapanda changed the title doc: url.resolve() method's behaviour doc: add url.resolve() method's behaviour Oct 9, 2016
@minervapanda
Copy link
Author

@addaleax Done :)

@addaleax
Copy link
Member

addaleax commented Oct 9, 2016

@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:

  • Check out your pr1 branch (I assume you have named it that way)
  • Make sure that the commit at the head of the branch is the one you want to edit, e.g. using git show
  • Edit the commit message using git commit --amend. That should give you an editor* and the way to change the message in whatever way you want
  • Add the add verb to the commit message, and ideally add a last line that says Fixes: https://github.com/nodejs/node/issues/8921
  • Once you’re happy with the changes, save the file and exit the editor.
  • Make sure the commit message looks like you want it to be like – again, using git show
  • If everything looks fine, push to this PR using git push --force-with-lease origin p1.

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 EDITOR=nano in the shell beforehand.)

doc/api/url.md Outdated

```js
url.resolve('https://foo.tld', 'bar') // 'https://foo.tld/bar'
url.resolve('wss://foo.tld', 'bar') // 'wss://bar'
Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

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.

Copy link
Member

@lpinca lpinca left a 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.
Copy link
Member

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!

@minervapanda
Copy link
Author

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 :
error: src refspec p1 does not match any.
error: failed to push some refs to 'https://github.com/minervapanda/node.git'

@addaleax
Copy link
Member

addaleax commented Oct 9, 2016

@minervapanda oh, yeah, that’s a typo, I meant pr1, not p1. 😄

Copy link

@rolinh rolinh left a 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.
Copy link

@rolinh rolinh Oct 10, 2016

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 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. 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)

Copy link
Author

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'
Copy link

@rolinh rolinh Oct 10, 2016

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'

```

Some protocols (`http`, `https`, `ftp`, `gopher` and `file`) are treated as special cases.
Copy link
Member

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!

@rvagg rvagg force-pushed the master branch 2 times, most recently from c133999 to 83c7a88 Compare October 18, 2016 17:02
@minervapanda
Copy link
Author

@addaleax when can this be merged to the master ?

Copy link
Member

@addaleax addaleax left a 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.
Copy link
Contributor

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.

Copy link
Author

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
Copy link
Contributor

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.
Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Member

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.

@sam-github
Copy link
Contributor

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.
Copy link
Member

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:

@italoacasas
Copy link
Contributor

ping @minervapanda

@jasnell jasnell added the stalled Issues and PRs that are stalled. label Mar 1, 2017
@fhinkel
Copy link
Member

fhinkel commented May 26, 2017

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.

@fhinkel fhinkel closed this May 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. stalled Issues and PRs that are stalled. url Issues and PRs related to the legacy built-in url module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants