Skip to content

Commit 1b41cd4

Browse files
jasnellrvagg
authored andcommitted
doc: discuss special protocol handling
Fixes: #13523 PR-URL: #22261 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Jon Moss <me@jonathanmoss.me>
1 parent cea8d4f commit 1b41cd4

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

doc/api/url.md

+40
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,46 @@ console.log(myURL.href);
389389

390390
Invalid URL protocol values assigned to the `protocol` property are ignored.
391391

392+
##### Special Schemes
393+
394+
The [WHATWG URL Standard][] considers a handful of URL protocol schemes to be
395+
_special_ in terms of how they are parsed and serialized. When a URL is
396+
parsed using one of these special protocols, the `url.protocol` property
397+
may be changed to another special protocol but cannot be changed to a
398+
non-special protocol, and vice versa.
399+
400+
For instance, changing from `http` to `https` works:
401+
402+
```js
403+
const u = new URL('http://example.org');
404+
u.protocol = 'https';
405+
console.log(u.href);
406+
// https://example.org
407+
```
408+
409+
However, changing from `http` to a hypothetical `fish` protocol does not
410+
because the new protocol is not special.
411+
412+
```js
413+
const u = new URL('http://example.org');
414+
u.protocol = 'fish';
415+
console.log(u.href);
416+
// http://example.org
417+
```
418+
419+
Likewise, changing from a non-special protocol to a special protocol is also
420+
not permitted:
421+
422+
```js
423+
const u = new URL('fish://example.org');
424+
u.protocol = 'http';
425+
console.log(u.href);
426+
// fish://example.org
427+
```
428+
429+
The protocol schemes considered to be special by the WHATWG URL Standard
430+
include: `ftp`, `file`, `gopher`, `http`, `https`, `ws`, and `wss`.
431+
392432
#### url.search
393433

394434
* {string}

0 commit comments

Comments
 (0)