-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
doc: explain edge case when assigning port to url #19645
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
Changes from 4 commits
d719151
2cc61c1
257eae0
e402ff4
64863ee
aedadce
a55b432
0d39ca6
92919bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -313,20 +313,39 @@ myURL.port = 1234.5678; | |
| console.log(myURL.port); | ||
| // Prints 1234 | ||
|
|
||
| // Out-of-range numbers are ignored | ||
| myURL.port = 1e10; | ||
| // Out-of-range numbers, which are not represented in scientific noation, | ||
| // will be ignored. | ||
| myURL.port = 1e10; // 10000000000, will be range-checked as described below | ||
| console.log(myURL.port); | ||
| // Prints 1234 | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this empty line seems redundant. |
||
| ``` | ||
|
|
||
| The port value may be set as either a number or as a String containing a number | ||
| in the range `0` to `65535` (inclusive). Setting the value to the default port | ||
| of the `URL` objects given `protocol` will result in the `port` value becoming | ||
| the empty string (`''`). | ||
|
|
||
| If an invalid string is assigned to the `port` property, but it begins with a | ||
| number, the leading number is assigned to `port`. Otherwise, or if the number | ||
| lies outside the range denoted above, it is ignored. | ||
| Upon assigning a value to the port, the value will first be converted to a string using `.toString()`. | ||
|
|
||
| If that string is invalid, but it begins with a | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why, but the wrapping of these two paragraphs creates hard wraps in the rendered text: https://github.com/nodeav/node/blob/e402ff4b54dd1eeb0cd0e7ce346751e97769c880/doc/api/url.md#urlport Maybe we can rewrap them with more long lines (but within 80 characters)?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I understand, in which line does the hard wrap occur?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, existing lines more than 80 chars is a temporal legacy, but now we have a rule in the STYLE_GUIDE.md and doc linting should throw on limit breaking.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see You have trailing spaces after some added lines, and markdown parses such spaces as hard breaks. It is usually useful to trim trailing spaces in the editor before saving the doc.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, the trailing spaces were actually intentional, but I don't mind changing that. and good to know about the line widths
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing spaces are not usually safe to rely upon in shared sources: some collaborator may edit any other line and have their editor set for trailing spaces auto-trimming in the whole doc, so these spaces may be deleted silently in any other PR)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there an actual designated docs linter? How do I run it? by the way, automatically removing trailing spaces for markdown documents is a bug IMO, as it's ignoring a part of the markdown language
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made sure the regex
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I am not mistaken. this is how to lint docs locally:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! The first one says there's nothing to be done; the second one passes. |
||
| number, the leading number is assigned to `port`. | ||
| Otherwise, or if the number | ||
| lies outside the range denoted above, it is ignored. | ||
|
|
||
| Note that numbers which contain a decimal point, | ||
| such as floating-point numbers or numbers in scientific notation, are not an exception to this rule. | ||
| Leading numbers up to the decimal point will be set as the url's port, assuming they are valid. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
|
|
||
| For example: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Remove this line and put a colon instead of a period after |
||
|
|
||
| ```js | ||
| myURL.port = 4.567e21; | ||
| console.log(myURL.port); | ||
| // Prints 4 (because it is the leading number in the string "4.567e21") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this empty line seems redundant. |
||
| ``` | ||
|
|
||
|
|
||
| #### url.protocol | ||
|
|
||
|
|
||

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: noation -> notation