Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornodeav <30617226+nodeav@users.noreply.github.com>2018-03-28 01:41:15 +0300
committerTrivikram Kamat <16024985+trivikr@users.noreply.github.com>2018-04-09 22:25:00 +0300
commit51c2c51029a05abb03c34929180a9c09c694ae2e (patch)
treeec296175b48fa4f9ef42c53cc96970cc5a6d0c47 /doc/api/url.md
parent3650972bfb17473b08c5bb32a65adb222355861a (diff)
doc: explain edge case when assigning port to url
numbers which are coerced to scientific notation via .toString(), will behave unexpectedly when assigned to a url's port. Fixes: https://github.com/nodejs/node/issues/19595 PR-URL: https://github.com/nodejs/node/pull/19645 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'doc/api/url.md')
-rw-r--r--doc/api/url.md27
1 files changed, 22 insertions, 5 deletions
diff --git a/doc/api/url.md b/doc/api/url.md
index 183631e64e0..a5a42ca7117 100644
--- a/doc/api/url.md
+++ b/doc/api/url.md
@@ -313,8 +313,9 @@ 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 notation
+// will be ignored.
+myURL.port = 1e10; // 10000000000, will be range-checked as described below
console.log(myURL.port);
// Prints 1234
```
@@ -324,9 +325,25 @@ 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 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:
+
+```js
+myURL.port = 4.567e21;
+console.log(myURL.port);
+// Prints 4 (because it is the leading number in the string '4.567e21')
+```
#### url.protocol