Skip to content

Commit ba11ad3

Browse files
ChALkeRjasnell
authored andcommitted
doc: use reserved domains for examples in url.md
Changes non-reserved domains to reserved ones in url.md. PR-URL: #23359 Refs: https://www.iana.org/domains/reserved Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent e6c310d commit ba11ad3

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

Diff for: doc/api/url.md

+48-48
Original file line numberDiff line numberDiff line change
@@ -26,47 +26,47 @@ backwards compatibility with existing applications. New application code
2626
should use the WHATWG API.
2727

2828
A comparison between the WHATWG and Legacy APIs is provided below. Above the URL
29-
`'http://user:pass@sub.host.com:8080/p/a/t/h?query=string#hash'`, properties of
30-
an object returned by the legacy `url.parse()` are shown. Below it are
29+
`'http://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash'`, properties
30+
of an object returned by the legacy `url.parse()` are shown. Below it are
3131
properties of a WHATWG `URL` object.
3232

3333
WHATWG URL's `origin` property includes `protocol` and `host`, but not
3434
`username` or `password`.
3535

3636
```txt
37-
┌─────────────────────────────────────────────────────────────────────────────────────────────┐
38-
│ href │
39-
├──────────┬──┬─────────────────────┬─────────────────────┬───────────────────────────┬───────┤
40-
│ protocol │ │ auth │ host │ path │ hash │
41-
│ │ │ ├──────────────┬──────┼──────────┬────────────────┤ │
42-
│ │ │ │ hostname │ port │ pathname │ search │ │
43-
│ │ │ │ │ │ ├─┬──────────────┤ │
44-
│ │ │ │ │ │ │ │ query │ │
45-
" https: // user : pass @ sub.host.com : 8080 /p/a/t/h ? query=string #hash "
46-
│ │ │ │ │ hostname │ port │ │ │ │
47-
│ │ │ │ ├──────────────┴──────┤ │ │ │
48-
│ protocol │ │ username │ password │ host │ │ │ │
49-
├──────────┴──┼──────────┴──────────┼─────────────────────┤ │ │ │
50-
│ origin │ │ origin │ pathname │ search │ hash │
51-
├─────────────┴─────────────────────┴─────────────────────┴──────────┴────────────────┴───────┤
52-
│ href │
53-
└─────────────────────────────────────────────────────────────────────────────────────────────┘
37+
┌────────────────────────────────────────────────────────────────────────────────────────────────
38+
href
39+
├──────────┬──┬─────────────────────┬────────────────────────┬───────────────────────────┬───────┤
40+
│ protocol │ │ auth │ host │ path │ hash │
41+
│ │ │ ├─────────────────┬──────┼──────────┬────────────────┤ │
42+
│ │ │ │ hostname │ port │ pathname │ search │ │
43+
│ │ │ │ │ │ ├─┬──────────────┤ │
44+
│ │ │ │ │ │ │ │ query │ │
45+
" https: // user : pass @ sub.example.com : 8080 /p/a/t/h ? query=string #hash "
46+
│ │ │ │ │ hostname │ port │ │ │ │
47+
│ │ │ │ ├─────────────────┴──────┤ │ │ │
48+
│ protocol │ │ username │ password │ host │ │ │ │
49+
├──────────┴──┼──────────┴──────────┼────────────────────────┤ │ │ │
50+
│ origin │ │ origin │ pathname │ search │ hash │
51+
├─────────────┴─────────────────────┴────────────────────────┴──────────┴────────────────┴───────┤
52+
href
53+
└────────────────────────────────────────────────────────────────────────────────────────────────
5454
(all spaces in the "" line should be ignored — they are purely for formatting)
5555
```
5656

5757
Parsing the URL string using the WHATWG API:
5858

5959
```js
6060
const myURL =
61-
new URL('https://user:pass@sub.host.com:8080/p/a/t/h?query=string#hash');
61+
new URL('https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash');
6262
```
6363

6464
Parsing the URL string using the Legacy API:
6565

6666
```js
6767
const url = require('url');
6868
const myURL =
69-
url.parse('https://user:pass@sub.host.com:8080/p/a/t/h?query=string#hash');
69+
url.parse('https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash');
7070
```
7171

7272
## The WHATWG URL API
@@ -120,8 +120,8 @@ Unicode characters appearing within the hostname of `input` will be
120120
automatically converted to ASCII using the [Punycode][] algorithm.
121121

122122
```js
123-
const myURL = new URL('https://你好你好');
124-
// https://xn--6qqa088eba/
123+
const myURL = new URL('https://測試');
124+
// https://xn--g6w251d/
125125
```
126126

127127
This feature is only available if the `node` executable was compiled with
@@ -132,23 +132,23 @@ and a `base` is provided, it is advised to validate that the `origin` of
132132
the `URL` object is what is expected.
133133

134134
```js
135-
let myURL = new URL('http://anotherExample.org/', 'https://example.org/');
136-
// http://anotherexample.org/
135+
let myURL = new URL('http://Example.com/', 'https://example.org/');
136+
// http://example.com/
137137

138-
myURL = new URL('https://anotherExample.org/', 'https://example.org/');
139-
// https://anotherexample.org/
138+
myURL = new URL('https://Example.com/', 'https://example.org/');
139+
// https://example.com/
140140

141-
myURL = new URL('foo://anotherExample.org/', 'https://example.org/');
142-
// foo://anotherExample.org/
141+
myURL = new URL('foo://Example.com/', 'https://example.org/');
142+
// foo://Example.com/
143143

144-
myURL = new URL('http:anotherExample.org/', 'https://example.org/');
145-
// http://anotherexample.org/
144+
myURL = new URL('http:Example.com/', 'https://example.org/');
145+
// http://example.com/
146146

147-
myURL = new URL('https:anotherExample.org/', 'https://example.org/');
148-
// https://example.org/anotherExample.org/
147+
myURL = new URL('https:Example.com/', 'https://example.org/');
148+
// https://example.org/Example.com/
149149

150-
myURL = new URL('foo:anotherExample.org/', 'https://example.org/');
151-
// foo:anotherExample.org/
150+
myURL = new URL('foo:Example.com/', 'https://example.org/');
151+
// foo:Example.com/
152152
```
153153

154154
#### url.hash
@@ -249,12 +249,12 @@ console.log(myURL.origin);
249249
```
250250

251251
```js
252-
const idnURL = new URL('https://你好你好');
252+
const idnURL = new URL('https://測試');
253253
console.log(idnURL.origin);
254-
// Prints https://xn--6qqa088eba
254+
// Prints https://xn--g6w251d
255255

256256
console.log(idnURL.hostname);
257-
// Prints xn--6qqa088eba
257+
// Prints xn--g6w251d
258258
```
259259

260260
#### url.password
@@ -929,16 +929,16 @@ any way. The `url.format(URL[, options])` method allows for basic customization
929929
of the output.
930930

931931
```js
932-
const myURL = new URL('https://a:b@你好你好?abc#foo');
932+
const myURL = new URL('https://a:b@測試?abc#foo');
933933

934934
console.log(myURL.href);
935-
// Prints https://a:b@xn--6qqa088eba/?abc#foo
935+
// Prints https://a:b@xn--g6w251d/?abc#foo
936936

937937
console.log(myURL.toString());
938-
// Prints https://a:b@xn--6qqa088eba/?abc#foo
938+
// Prints https://a:b@xn--g6w251d/?abc#foo
939939

940940
console.log(url.format(myURL, { fragment: false, unicode: true, auth: false }));
941-
// Prints 'https://你好你好/?abc'
941+
// Prints 'https://測試/?abc'
942942
```
943943

944944
### url.pathToFileURL(path)
@@ -999,21 +999,21 @@ For example: `'#hash'`.
999999
The `host` property is the full lower-cased host portion of the URL, including
10001000
the `port` if specified.
10011001

1002-
For example: `'sub.host.com:8080'`.
1002+
For example: `'sub.example.com:8080'`.
10031003

10041004
#### urlObject.hostname
10051005

10061006
The `hostname` property is the lower-cased host name portion of the `host`
10071007
component *without* the `port` included.
10081008

1009-
For example: `'sub.host.com'`.
1009+
For example: `'sub.example.com'`.
10101010

10111011
#### urlObject.href
10121012

10131013
The `href` property is the full URL string that was parsed with both the
10141014
`protocol` and `host` components converted to lower-case.
10151015

1016-
For example: `'http://user:pass@sub.host.com:8080/p/a/t/h?query=string#hash'`.
1016+
For example: `'http://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash'`.
10171017

10181018
#### urlObject.path
10191019

@@ -1282,11 +1282,11 @@ using the [Punycode][] algorithm. Note, however, that a hostname *may* contain
12821282
*both* Punycode encoded and percent-encoded characters:
12831283

12841284
```js
1285-
const myURL = new URL('https://%CF%80.com/foo');
1285+
const myURL = new URL('https://%CF%80.example.com/foo');
12861286
console.log(myURL.href);
1287-
// Prints https://xn--1xa.com/foo
1287+
// Prints https://xn--1xa.example.com/foo
12881288
console.log(myURL.origin);
1289-
// Prints https://π.com
1289+
// Prints https://π.example.com
12901290
```
12911291

12921292
[`Error`]: errors.html#errors_class_error

0 commit comments

Comments
 (0)