/
url.html
5103 lines (3716 loc) · 223 KB
/
url.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>URL Standard</title>
<link href="https://www.whatwg.org/style/specification" rel="stylesheet">
<link href="https://resources.whatwg.org/bikeshed.css" rel="stylesheet">
<link href="https://resources.whatwg.org/logo-url.svg" rel="icon">
<meta content="Bikeshed 1.0.0" name="generator">
</head>
<body class="h-entry status-LS">
<div class="head">
<p data-fill-with="logo"><a class="logo" href="https://whatwg.org/">
<img alt="WHATWG" height="100" src="https://resources.whatwg.org/logo-url.svg">
</a>
</p>
<h1 class="p-name no-ref allcaps" id="title">URL</h1>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Living Standard — Last Updated
<time class="dt-updated" datetime="2015-08-16">16 August 2015</time></span></h2>
<div data-fill-with="spec-metadata">
<dl>
<dt>Participate:
<dd><span><a href="https://github.com/whatwg/url">GitHub whatwg/url</a> (<a href="https://github.com/whatwg/url/issues/new">new issue</a>, <a href="https://github.com/whatwg/url/issues">open issues</a>, <a href="https://www.w3.org/Bugs/Public/buglist.cgi?product=WHATWG&component=URL&resolution=---">legacy open bugs</a>)</span>
<dd><span><a href="https://wiki.whatwg.org/wiki/IRC">IRC: #whatwg on Freenode</a></span>
<dt>Commits:
<dd><span><a href="https://github.com/whatwg/url/commits">https://github.com/whatwg/url/commits</a></span>
<dd><span><a href="https://twitter.com/urlstandard">@urlstandard</a></span>
</dl>
</div>
<div data-fill-with="warning"></div>
</div>
<h2 class="no-num no-toc no-ref heading settled" id="abstract"><span class="content">Abstract</span></h2>
<div class="p-summary" data-fill-with="abstract">
<p>The URL Standard defines URLs, domains, IP addresses, the <code title="">application/x-www-form-urlencoded</code> format, and their API.</p>
</div>
<div data-fill-with="at-risk"></div>
<h2 class="no-num no-toc no-ref heading settled" id="contents"><span class="content">Table of Contents</span></h2>
<div data-fill-with="table-of-contents" role="navigation">
<ul class="toc" role="directory">
<li><a href="#goals"><span class="secno"></span> <span class="content">Goals</span></a>
<li><a href="#terminology"><span class="secno">1</span> <span class="content">Terminology</span></a>
<ul class="toc">
<li><a href="#parsers"><span class="secno">1.1</span> <span class="content">Parsers</span></a>
</ul>
<li><a href="#percent-encoded-bytes"><span class="secno">2</span> <span class="content">Percent-encoded bytes</span></a>
<li><a href="#hosts-(domains-and-ip-addresses)"><span class="secno">3</span> <span class="content">Hosts (domains and IP addresses)</span></a>
<ul class="toc">
<li><a href="#idna"><span class="secno">3.1</span> <span class="content">IDNA</span></a>
<li><a href="#host-syntax"><span class="secno">3.2</span> <span class="content">Host syntax</span></a>
<li><a href="#host-parsing"><span class="secno">3.3</span> <span class="content">Host parsing</span></a>
<li><a href="#host-serializing"><span class="secno">3.4</span> <span class="content">Host serializing</span></a>
</ul>
<li><a href="#urls"><span class="secno">4</span> <span class="content">URLs</span></a>
<ul class="toc">
<li><a href="#url-syntax"><span class="secno">4.1</span> <span class="content">URL syntax</span></a>
<li><a href="#url-parsing"><span class="secno">4.2</span> <span class="content">URL parsing</span></a>
<li><a href="#url-serializing"><span class="secno">4.3</span> <span class="content">URL serializing</span></a>
<li><a href="#url-equivalence"><span class="secno">4.4</span> <span class="content">URL equivalence</span></a>
<li><a href="#origin"><span class="secno">4.5</span> <span class="content">Origin</span></a>
</ul>
<li><a href="#application/x-www-form-urlencoded"><span class="secno">5</span> <span class="content"><code data-lt="application-x-www-form-urlencoded-0"><span>application/x-www-form-urlencoded</span></code></span></a>
<ul class="toc">
<li><a href="#urlencoded-parsing"><span class="secno">5.1</span> <span class="content"><code data-lt="application-x-www-form-urlencoded-0">application/x-www-form-urlencoded</code> parsing</span></a>
<li><a href="#urlencoded-serializing"><span class="secno">5.2</span> <span class="content"><code data-lt="application-x-www-form-urlencoded-0">application/x-www-form-urlencoded</code> serializing</span></a>
<li><a href="#urlencoded-hooks"><span class="secno">5.3</span> <span class="content">Hooks</span></a>
</ul>
<li><a href="#api"><span class="secno">6</span> <span class="content">API</span></a>
<ul class="toc">
<li><a href="#constructors"><span class="secno">6.1</span> <span class="content">Constructors</span></a>
<li><a href="#url-statics"><span class="secno">6.2</span> <span class="content"><code class="idl"><span>URL</span></code> statics</span></a>
<li><a href="#urlutils-and-urlutilsreadonly-members"><span class="secno">6.3</span> <span class="content"><code class="idl"><span>URLUtils</span></code>/<code class="idl"><span>URLUtilsSearchParams</span></code> and <code class="idl"><span>URLUtilsReadOnly</span></code> members</span></a>
<li><a href="#interface-urlsearchparams"><span class="secno">6.4</span> <span class="content">Interface <code class="idl"><span>URLSearchParams</span></code></span></a>
<li><a href="#url-apis-elsewhere"><span class="secno">6.5</span> <span class="content">URL APIs elsewhere</span></a>
</ul>
<li><a href="#acknowledgments"><span class="secno"></span> <span class="content">Acknowledgments</span></a>
<li><a href="#conformance"><span class="secno"></span> <span class="content">Conformance</span></a>
<li><a href="#index"><span class="secno"></span> <span class="content">Index</span></a>
<ul class="toc">
<li><a href="#index-defined-here"><span class="secno"></span> <span class="content">Terms defined by this specification</span></a>
<li><a href="#index-defined-elsewhere"><span class="secno"></span> <span class="content">Terms defined by reference</span></a>
</ul>
<li><a href="#references"><span class="secno"></span> <span class="content">References</span></a>
<ul class="toc">
<li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a>
<li><a href="#informative"><span class="secno"></span> <span class="content">Informative References</span></a>
</ul>
<li><a href="#idl-index"><span class="secno"></span> <span class="content">IDL Index</span></a>
</ul></div>
<main>
<script async="" src="https://resources.whatwg.org/file-issue.js"></script>
<script defer="" id="head" src="https://resources.whatwg.org/dfn.js"></script>
<h2 class="no-num heading settled" id="goals"><span class="content">Goals</span></h2>
<p>The URL standard takes the following approach towards making URLs fully interoperable:
</p>
<ul>
<li>
<p>Align RFC 3986 and RFC 3987 with contemporary implementations and
obsolete them in the process. (E.g., spaces, other "illegal" code points,
query encoding, equality, canonicalization, are all concepts not entirely
shared, or defined.) URL parsing needs to become as solid as HTML parsing.
<a data-link-type="biblio" href="#biblio-rfc3986">[RFC3986]</a>
<a data-link-type="biblio" href="#biblio-rfc3987">[RFC3987]</a>
</p>
<li>
<p>Standardize on the term URL. URI and IRI are just confusing. In
practice a single algorithm is used for both so keeping them distinct is
not helping anyone. URL also easily wins the
<a href="http://www.googlefight.com/index.php?word1=url&word2=uri">search result popularity contest</a>.
</p>
<li>
<p>Supplanting <a href="https://tools.ietf.org/html/rfc6454#section-4">Origin of a URI [sic]</a>.
<a data-link-type="biblio" href="#biblio-rfc6454">[RFC6454]</a>
</p>
<li>
<p>Define URL’s existing JavaScript API in full detail and add
enhancements to make it easier to work with. Add a new <code><a class="idl-code" data-link-type="interface" href="#url">URL</a></code>
object as well for URL manipulation without usage of HTML elements. (Useful
for JavaScript worker environments.)
</p></ul>
<p class="note" role="note">As the editors learn more about the subject matter the goals
might increase in scope somewhat.
</p>
<h2 class="heading settled" data-level="1" id="terminology"><span class="secno">1. </span><span class="content">Terminology</span><a class="self-link" href="#terminology"></a></h2>
<p>Some terms used in this specification are defined in the
DOM, Encoding, IDNA, and Web IDL Standards.
<a data-link-type="biblio" href="#biblio-dom">[DOM]</a>
<a data-link-type="biblio" href="#biblio-encoding">[ENCODING]</a>
<a data-link-type="biblio" href="#biblio-idna">[IDNA]</a>
<a data-link-type="biblio" href="#biblio-webidl">[WEBIDL]</a>
</p>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="c0-controls">C0 controls<a class="self-link" href="#c0-controls"></a></dfn> are code points in the range U+0000 to U+001F, inclusive.
</p>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="c0-controls-and-space">C0 controls and space<a class="self-link" href="#c0-controls-and-space"></a></dfn> are <a data-link-type="dfn" href="#c0-controls">C0 controls</a> and code point U+0020.
</p>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="ascii-digits">ASCII digits<a class="self-link" href="#ascii-digits"></a></dfn> are code points in the range U+0030 to U+0039, inclusive.
</p>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="ascii-hex-digits">ASCII hex digits<a class="self-link" href="#ascii-hex-digits"></a></dfn> are <a data-link-type="dfn" href="#ascii-digits">ASCII digits</a>, code points in the range
U+0041 to U+0046, inclusive, and code points in the range U+0061 to U+0066, inclusive.
</p>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="ascii-alpha">ASCII alpha<a class="self-link" href="#ascii-alpha"></a></dfn> are code points in the range U+0041 to U+005A, inclusive,
and in the range U+0061 to U+007A, inclusive.
</p>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="ascii-alphanumeric">ASCII alphanumeric<a class="self-link" href="#ascii-alphanumeric"></a></dfn> are <a data-link-type="dfn" href="#ascii-digits">ASCII digits</a> and <a data-link-type="dfn" href="#ascii-alpha">ASCII alpha</a>.
</p>
<p>An <dfn data-dfn-type="dfn" data-noexport="" id="ascii-string">ASCII string<a class="self-link" href="#ascii-string"></a></dfn> is a <a data-link-type="dfn" href="https://encoding.spec.whatwg.org/#string">string</a> in the range U+0000 to U+007F, inclusive.
</p>
<p>To <dfn data-dfn-type="dfn" data-noexport="" id="ascii-lowercase">ASCII lowercase<a class="self-link" href="#ascii-lowercase"></a></dfn> a <a data-link-type="dfn" href="https://encoding.spec.whatwg.org/#string">string</a>, replace all code points in the range
U+0041 to U+005A, inclusive, with the corresponding code points in the range
U+0061 to U+007A, inclusive.
</p>
<hr>
<p>To <dfn data-dfn-type="dfn" data-noexport="" id="serialize-an-integer">serialize an integer<a class="self-link" href="#serialize-an-integer"></a></dfn>, represent it as the shortest possible decimal
number.
</p>
<hr>
<p>A <dfn data-dfn-type="dfn" data-noexport="" id="potential-windows-drive-letter">potential Windows drive letter<a class="self-link" href="#potential-windows-drive-letter"></a></dfn> is two code points, of which the first is
an <a data-link-type="dfn" href="#ascii-alpha">ASCII alpha</a> and the second is either "<code>:</code>" or "<code>|</code>".
</p>
<p>A <dfn data-dfn-type="dfn" data-noexport="" id="windows-drive-letter">Windows drive letter<a class="self-link" href="#windows-drive-letter"></a></dfn> is a <a data-link-type="dfn" href="#potential-windows-drive-letter">potential Windows drive letter</a> of which
the second code point is "<code>:</code>".
</p>
<h3 class="heading settled" data-level="1.1" id="parsers"><span class="secno">1.1. </span><span class="content">Parsers</span><a class="self-link" href="#parsers"></a></h3>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="eof-code-point">EOF code point<a class="self-link" href="#eof-code-point"></a></dfn> is a conceptual code point that signifies the end of a
string or code point stream.
</p>
<p>Within a parser algorithm that uses a <var>pointer</var> variable, <dfn data-dfn-type="dfn" data-noexport="" id="c">c<a class="self-link" href="#c"></a></dfn>
references the code point the <var>pointer</var> variable points to.
</p>
<p>Within a string-based parser algorithm that uses a <var>pointer</var> variable,
<dfn data-dfn-type="dfn" data-noexport="" id="remaining">remaining<a class="self-link" href="#remaining"></a></dfn> references the substring after <var>pointer</var> in the string
being processed.
</p>
<p class="example" id="example-12672b6a"><a class="self-link" href="#example-12672b6a"></a>If "<code>mailto:username@example</code>" is a string being
processed and <var>pointer</var> points to "<code>@</code>",
<a data-link-type="dfn" href="#c">c</a> is "<code>@</code>" and <a data-link-type="dfn" href="#remaining">remaining</a> is
"<code>example</code>".
</p>
<p>A <dfn data-dfn-type="dfn" data-noexport="" id="syntax-violation">syntax violation<a class="self-link" href="#syntax-violation"></a></dfn> indicates a non-fatal mismatch between input and syntax
requirements. User agents, especially conformance checkers are encouraged to report them
somewhere.
</p>
<p class="note no-backref" role="note">A <a data-link-type="dfn" href="#syntax-violation">syntax violation</a> does not mean that the parser
terminates. Termination of a parser is always stated explicitly. E.g., through a return
statement.
</p>
<h2 class="heading settled" data-level="2" id="percent-encoded-bytes"><span class="secno">2. </span><span class="content">Percent-encoded bytes</span><a class="self-link" href="#percent-encoded-bytes"></a></h2>
<p>A <dfn data-dfn-type="dfn" data-noexport="" id="percent_encoded-byte">percent-encoded byte<a class="self-link" href="#percent_encoded-byte"></a></dfn> is "<code>%</code>", followed by
two <a data-link-type="dfn" href="#ascii-hex-digits">ASCII hex digits</a>. Sequences of
<a data-link-type="dfn" href="#percent_encoded-byte">percent-encoded bytes</a>, after
conversion to bytes, should not cause a
<a data-link-type="dfn" href="https://encoding.spec.whatwg.org/#utf-8-decoder">utf-8 decoder</a> to run into any
<a data-link-type="dfn" href="https://encoding.spec.whatwg.org/#error">errors</a>.
</p>
<p>To <dfn data-dfn-type="dfn" data-noexport="" id="percent-encode">percent encode<a class="self-link" href="#percent-encode"></a></dfn> a <var>byte</var> into a
<a data-link-type="dfn" href="#percent_encoded-byte">percent-encoded byte</a>, return a string consisting of
"<code>%</code>", followed by a double-digit, uppercase, hexadecimal
representation of <var>byte</var>.
</p>
<p>To <dfn data-dfn-type="dfn" data-noexport="" id="percent-decode">percent decode<a class="self-link" href="#percent-decode"></a></dfn> a byte sequence <var>input</var>, run these steps:
</p>
<p class="warning">Using anything but a <a data-link-type="dfn" href="https://encoding.spec.whatwg.org/#utf-8-decoder">utf-8 decoder</a>
when the <var>input</var> contains bytes outside the range 0x00 to 0x7F might be
insecure and is not recommended.
</p>
<ol>
<li>
<p>Let <var>output</var> be an empty byte sequence.
</p>
<li>
<p>For each byte <var>byte</var> in <var>input</var>, run these steps:
</p>
<ol>
<li>
<p>If <var>byte</var> is not `<code>%</code>`, append
<var>byte</var> to <var>output</var>.
</p>
<li>
<p>Otherwise, if <var>byte</var> is `<code>%</code>` and the next two
bytes after <var>byte</var> in <var>input</var> are not in the ranges
0x30 to 0x39, 0x41 to 0x46, and 0x61 to 0x66, append <var>byte</var> to
<var>output</var>.
</p>
<li>
<p>Otherwise, run these substeps:
</p>
<ol>
<li>
<p>Let <var>bytePoint</var> be the two bytes after <var>byte</var> in
<var>input</var>,
<a data-link-type="dfn" href="https://encoding.spec.whatwg.org/#utf-8-decode-without-bom">decoded</a>, and
then interpreted as hexadecimal number.
</p>
<li>
<p>Append a byte whose value is <var>bytePoint</var> to
<var>output</var>.
</p>
<li>
<p>Skip the next two bytes in <var>input</var>.
</p>
</ol>
</ol>
<li>
<p>Return <var>output</var>.
</p></ol>
<p></p>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="simple-encode-set">simple encode set<a class="self-link" href="#simple-encode-set"></a></dfn> are <a data-link-type="dfn" href="#c0-controls">C0 controls</a> and all code points greater
than U+007E.
</p>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="default-encode-set">default encode set<a class="self-link" href="#default-encode-set"></a></dfn> is the
<a data-link-type="dfn" href="#simple-encode-set">simple encode set</a> and code points U+0020,
'<code>"</code>',
"<code>#</code>",
"<code><</code>",
"<code>></code>",
"<code>?</code>",
"<code>`</code>",
"<code>{</code>",
and
"<code>}</code>".
</p>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="userinfo-encode-set">userinfo encode set<a class="self-link" href="#userinfo-encode-set"></a></dfn> is the
<a data-link-type="dfn" href="#default-encode-set">default encode set</a> and code points
"<code>/</code>",
"<code>:</code>",
"<code>;</code>",
"<code>=</code>",
"<code>@</code>",
"<code>[</code>",
"<code>\</code>",
"<code>]</code>",
"<code>^</code>",
and
"<code>|</code>".
</p>
<p>To <dfn data-dfn-type="dfn" data-noexport="" id="utf_8-percent-encode">utf-8 percent encode<a class="self-link" href="#utf_8-percent-encode"></a></dfn> a <var>codePoint</var>, using
an <var>encode set</var>, run these steps:
</p>
<ol>
<li>
<p>If <var>codePoint</var> is not in <var>encode set</var>, return
<var>codePoint</var>.
</p>
<li>
<p>Let <var>bytes</var> be the result of running <a data-link-type="dfn" href="https://encoding.spec.whatwg.org/#utf-8-encode">utf-8 encode</a> on
<var>codePoint</var>.
</p>
<li>
<p><a data-link-type="dfn" href="#percent-encode">Percent encode</a> each byte in <var>bytes</var>, and then return the results
concatenated, in the same order.
</p></ol>
<h2 class="heading settled" data-level="3" id="hosts-(domains-and-ip-addresses)"><span class="secno">3. </span><span class="content">Hosts (domains and IP addresses)</span><a class="self-link" href="#hosts-%28domains-and-ip-addresses%29"></a></h2>
<p>A <dfn data-dfn-for="host" data-dfn-type="dfn" data-export="" id="concept-host">host<a class="self-link" href="#concept-host"></a></dfn> is a <a data-link-type="dfn" href="#concept-domain">domain</a>, an
<a data-link-type="dfn" href="#concept-ipv4">IPv4 address</a>, or an <a data-link-type="dfn" href="#concept-ipv6">IPv6 address</a>. Typically a
<a data-link-type="dfn" href="#concept-host">host</a> serves as a network address, but it is sometimes (ab)used as opaque
identifier in <a data-link-type="dfn" href="#concept-url">URLs</a> where a network address is not necessary.
</p>
<p>A <dfn data-dfn-for="host" data-dfn-type="dfn" data-export="" id="concept-domain">domain<a class="self-link" href="#concept-domain"></a></dfn> identifies a realm within a
network.
<a data-link-type="biblio" href="#biblio-rfc1034">[RFC1034]</a>
</p>
<p>An <dfn data-dfn-for="host" data-dfn-type="dfn" data-export="" id="concept-ipv4">IPv4 address<a class="self-link" href="#concept-ipv4"></a></dfn> is a 32-bit identifier.
<a data-link-type="biblio" href="#biblio-rfc791">[RFC791]</a>
</p>
<p>An <dfn data-dfn-for="host" data-dfn-type="dfn" data-export="" id="concept-ipv6">IPv6 address<a class="self-link" href="#concept-ipv6"></a></dfn> is a 128-bit identifier and
for the purposes of this specification represented as an ordered list of
eight <dfn data-dfn-type="dfn" data-lt="IPv6 piece" data-noexport="" id="concept-ipv6-piece">16-bit pieces<a class="self-link" href="#concept-ipv6-piece"></a></dfn>.
<a data-link-type="biblio" href="#biblio-rfc4291">[RFC4291]</a>
</p>
<p class="note" role="note">Support for <code><zone_id></code> is
<a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=27234#c2">intentionally omitted</a>.
</p>
<h3 class="heading settled" data-level="3.1" id="idna"><span class="secno">3.1. </span><span class="content">IDNA</span><a class="self-link" href="#idna"></a></h3>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="concept-domain-to-ascii">domain to ASCII<a class="self-link" href="#concept-domain-to-ascii"></a></dfn> given a
<a data-link-type="dfn" href="#concept-domain">domain</a> <var>domain</var>, runs these steps:
</p>
<ol>
<li>
<p>Let <var>result</var> be the result of running
<a data-link-type="dfn" href="http://www.unicode.org/reports/tr46/#ToASCII">Unicode ToASCII</a> with
<i>domain_name</i> set to <var>domain</var>,
<i>UseSTD3ASCIIRules</i> set to false, <i>processing_option</i> set to
<i>Transitional_Processing</i>, and <i>VerifyDnsLength</i> set to false.
</p>
<li>
<p>If <var>result</var> is a failure value, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>, return failure.
</p>
<li>
<p>Return <var>result</var>.
</p></ol>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="concept-domain-to-unicode">domain to Unicode<a class="self-link" href="#concept-domain-to-unicode"></a></dfn> given a
<a data-link-type="dfn" href="#concept-domain">domain</a> <var>domain</var>, runs these steps:
</p>
<ol>
<li>
<p>Let <var>result</var> be the result of running
<a data-link-type="dfn" href="http://www.unicode.org/reports/tr46/#ToUnicode">Unicode ToUnicode</a> with
<i>domain_name</i> set to <var>domain</var>,
<i>UseSTD3ASCIIRules</i> set to false.
</p>
<li>
<p>Signify <a data-link-type="dfn" href="#syntax-violation">syntax violations</a> for any returned errors, and then, return
<var>result</var>.
</p></ol>
<h3 class="heading settled" data-level="3.2" id="host-syntax"><span class="secno">3.2. </span><span class="content">Host syntax</span><a class="self-link" href="#host-syntax"></a></h3>
<p>A <dfn data-dfn-for="hostsyntax" data-dfn-type="dfn" data-export="" id="syntax-host">host<a class="self-link" href="#syntax-host"></a></dfn> must be a
<a data-link-type="dfn" href="#syntax-host-domain">domain</a>, an <a data-link-type="dfn" href="#syntax-host-ipv4">IPv4 address</a>, or "<code>[</code>",
followed by an <a data-link-type="dfn" href="#syntax-host-ipv6">IPv6 address</a>, followed by "<code>]</code>".
</p>
<p>A <var>domain</var> is a <dfn data-dfn-type="dfn" data-noexport="" id="valid-domain">valid domain<a class="self-link" href="#valid-domain"></a></dfn> if these steps return success:
</p>
<ol>
<li>
<p>Let <var>result</var> be the result of running
<a data-link-type="dfn" href="http://www.unicode.org/reports/tr46/#ToASCII">Unicode ToASCII</a> with
<i>domain_name</i> set to <var>domain</var>,
<i>UseSTD3ASCIIRules</i> set to true, <i>processing_option</i> set to
<i>Nontransitional_Processing</i>, and <i>VerifyDnsLength</i> set to true.
</p>
<li>
<p>If <var>result</var> is a failure value, return failure.
</p>
<li>
<p>Set <var>result</var> to the result of running
<a data-link-type="dfn" href="http://www.unicode.org/reports/tr46/#ToUnicode">Unicode ToUnicode</a> with
<i>domain_name</i> set to <var>result</var>,
<i>UseSTD3ASCIIRules</i> set to true.
</p>
<li>
<p>If <var>result</var> contains any errors, return failure.
</p>
<li>
<p>Return success.
</p></ol>
<p class="XXX">Ideally we define this in terms of a sequence of code points that make up a
<a data-link-type="dfn" href="#valid-domain">valid domain</a> rather than through a whack-a-mole:
<a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=25334">bug 25334</a>.
</p>
<p>A <dfn data-dfn-for="hostsyntax" data-dfn-type="dfn" data-export="" id="syntax-host-domain">domain<a class="self-link" href="#syntax-host-domain"></a></dfn> must be a string that
is a <a data-link-type="dfn" href="#valid-domain">valid domain</a>.
</p>
<p>An <dfn data-dfn-for="hostsyntax" data-dfn-type="dfn" data-export="" id="syntax-host-ipv4">IPv4 address<a class="self-link" href="#syntax-host-ipv4"></a></dfn> must be four
sequences of up to three <span>ASCII digits</span> per sequence, each representing a
number no greater than 255, and separated from each other by "<code>.</code>".
</p>
<p>An <dfn data-dfn-for="hostsyntax" data-dfn-type="dfn" data-export="" id="syntax-host-ipv6">IPv6 address<a class="self-link" href="#syntax-host-ipv6"></a></dfn> is defined in the
<a href="https://tools.ietf.org/html/rfc4291#section-2.2">"Text Representation of Addresses" chapter of IP Version 6 Addressing Architecture</a>.
<a data-link-type="biblio" href="#biblio-rfc4291">[RFC4291]</a>
</p>
<h3 class="heading settled" data-level="3.3" id="host-parsing"><span class="secno">3.3. </span><span class="content">Host parsing</span><a class="self-link" href="#host-parsing"></a></h3>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="concept-host-parser">host parser<a class="self-link" href="#concept-host-parser"></a></dfn> takes a string <var>input</var> and
an optional <var>Unicode flag</var> (unset unless stated otherwise), and then runs these
steps:
</p>
<ol>
<li>
<p>If <var>input</var> starts with "<code>[</code>", run these
substeps:
</p>
<ol>
<li>
<p>If <var>input</var> does not end with
"<code>]</code>", <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>, return failure.
</p>
<li>
<p>Return the result of
<a data-link-type="dfn" href="#concept-ipv6-parser">IPv6 parsing</a> <var>input</var>
with its leading "<code>[</code>" and trailing
"<code>]</code>" removed.
</p>
</ol>
<li>
<p>Let <var>domain</var> be the result of
<a data-link-type="dfn" href="https://encoding.spec.whatwg.org/#utf-8-decode-without-bom">utf-8 decode without BOM</a> on the
<a data-link-type="dfn" href="#percent-decode">percent decoding</a> of
<a data-link-type="dfn" href="https://encoding.spec.whatwg.org/#utf-8-encode">utf-8 encode</a> on <var>input</var>.
</p>
<li>
<p>Let <var>asciiDomain</var> be the result of running
<a data-link-type="dfn" href="#concept-domain-to-ascii">domain to ASCII</a> on <var>domain</var>.
</p>
<li>
<p>If <var>asciiDomain</var> is failure, return failure.
</p>
<li>
<p>If <var>asciiDomain</var> contains one of
U+0000,
U+0009,
U+000A,
U+000D,
U+0020,
"<code>#</code>",
"<code>%</code>",
"<code>/</code>",
"<code>:</code>",
"<code>?</code>",
"<code>@</code>",
"<code>[</code>",
"<code>\</code>",
and
"<code>]</code>",
<a data-link-type="dfn" href="#syntax-violation">syntax violation</a>, return failure.
</p>
<li>
<p>Let <var>ipv4Host</var> be the result of <a data-link-type="dfn" href="#concept-ipv4-parser">IPv4 parsing</a>
<var>asciiDomain</var>.
</p>
<li>
<p>If <var>ipv4Host</var> is an <a data-link-type="dfn" href="#concept-ipv4">IPv4 address</a> or failure, return
<var>ipv4Host</var>.
</p>
<li>
<p>Return <var>asciiDomain</var> if the <var>Unicode flag</var> is unset, and the
result of running <a data-link-type="dfn" href="#concept-domain-to-unicode">domain to Unicode</a> on <var>asciiDomain</var> otherwise.
</p></ol>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="ipv4-number-parser">IPv4 number parser<a class="self-link" href="#ipv4-number-parser"></a></dfn> takes a string <var>input</var> and then runs these
steps:</p>
<ol>
<li>
<p>Let <var>R</var> be 10.
</p>
<li>
<p>If <var>input</var> contains at least two code points and the first two code points
are either "<code>0x</code>" or "<code>0X</code>", run these substeps:
</p>
<ol>
<li>
<p>Remove the first two code points from <var>input</var>.
</p>
<li>
<p>Set <var>R</var> to 16.
</p>
</ol>
<li>
<p>If <var>input</var> is the empty string, return zero.
</p>
<li>
<p>Otherwise, if <var>input</var> contains at least two code points and the first code
point is "<code>0</code>", run these substeps:
</p>
<ol>
<li>
<p>Remove the first code point from <var>input</var>.
</p>
<li>
<p>Set <var>R</var> to 8.
</p>
</ol>
<li>
<p>If <var>input</var> contains a code point that is not a radix-<var>R</var> digit,
return failure.
</p>
<li>
<p>Return the mathematical integer value that is represented by <var>input</var> in
radix-<var>R</var> notation, using <a data-link-type="dfn" href="#ascii-hex-digits">ASCII hex digits</a> for digits with values 0
through 15.
</p></ol>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="concept-ipv4-parser">IPv4 parser<a class="self-link" href="#concept-ipv4-parser"></a></dfn> takes a string <var>input</var> and then
runs these steps:</p>
<ol>
<li>
<p>Let <var>parts</var> be <var>input</var> split on "<code>.</code>".
</p>
<li>
<p>If the last item in <var>parts</var> is the empty string, remove it from
<var>parts</var>.
</p>
<li>
<p>If <var>parts</var> has more than four items, return <var>input</var>.
</p>
<li>
<p>Let <var>numbers</var> be the empty list.
</p>
<li>
<p>For each <var>part</var> in <var>parts</var>:
</p>
<ol>
<li>
<p>If <var>part</var> is the empty string, return <var>input</var>.
</p>
<p class="example no-backref" id="example-c2afe535"><a class="self-link" href="#example-c2afe535"></a><code>0..0x300</code> is a <a data-link-type="dfn" href="#concept-domain">domain</a>, not
an <a data-link-type="dfn" href="#concept-ipv4">IPv4 address</a>.
</p>
<li>
<p>Let <var>n</var> be the result of <a data-link-type="dfn" href="#ipv4-number-parser">parsing</a>
<var>part</var>.
</p>
<li>
<p>If <var>n</var> is failure, return <var>input</var>.
</p>
<li>
<p>Append <var>n</var> to <var>numbers</var>.
</p>
</ol>
<li>
<p>If any but the last item in <var>numbers</var> is greater than 255,
<a data-link-type="dfn" href="#syntax-violation">syntax violation</a> return failure.
</p>
<li>
<p>If the last item in <var>numbers</var> is greater than or equal to
256<sup>(5 − the number of items in <var>numbers</var>)</sup>,
<a data-link-type="dfn" href="#syntax-violation">syntax violation</a>, return failure.
</p>
<li>
<p>Let <var>ipv4</var> be the last item in <var>numbers</var>.
</p>
<li>
<p>Remove the last item from <var>numbers</var>.
</p>
<li>
<p>Let <var>counter</var> be zero.
</p>
<li>
<p>For each <var>n</var> in <var>numbers</var>:
</p>
<ol>
<li>
<p>Increment <var>ipv4</var> by <var>n</var> ×
256<sup>(3 − <var>counter</var>)</sup>.
</p>
<li>
<p>Increment <var>counter</var> by one.
</p>
</ol>
<li>
<p>Return <var>ipv4</var>.
</p></ol>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="concept-ipv6-parser">IPv6 parser<a class="self-link" href="#concept-ipv6-parser"></a></dfn> takes a string <var>input</var> and
then runs these steps:
</p>
<ol>
<li>
<p>Let <var>address</var> be a new <a data-link-type="dfn" href="#concept-ipv6">IPv6 address</a> with its
<a data-link-type="dfn" href="#concept-ipv6-piece">16-bit pieces</a> initialized to 0.
</p>
<li>
<p>Let <var>piece pointer</var> be a pointer into
<var>address</var>’s
<a data-link-type="dfn" href="#concept-ipv6-piece">16-bit pieces</a>, initially zero
(pointing to the first <a data-link-type="dfn" href="#concept-ipv6-piece">16-bit piece</a>),
and let <var>piece</var> be the
<a data-link-type="dfn" href="#concept-ipv6-piece">16-bit piece</a> it points to.
</p>
<li>
<p>Let <var>compress pointer</var> be another pointer into
<var>address</var>’s <a data-link-type="dfn" href="#concept-ipv6-piece">16-bit pieces</a>, initially
null and pointing to nothing.
</p>
<li>
<p>Let <var>pointer</var> be a pointer into
<var>input</var>, initially zero (pointing to the first code point).
</p>
<li>
<p>If <a data-link-type="dfn" href="#c">c</a> is "<code>:</code>", run these substeps:
</p>
<ol>
<li>
<p>If <a data-link-type="dfn" href="#remaining">remaining</a> does not start with "<code>:</code>",
<a data-link-type="dfn" href="#syntax-violation">syntax violation</a>, return failure.
</p>
<li>
<p>Increase <var>pointer</var> by two.
</p>
<li>
<p>Increase <var>piece pointer</var> by one and then set
<var>compress pointer</var> to <var>piece pointer</var>.
</p>
</ol>
<li>
<p><dfn data-dfn-type="dfn" data-lt="IPv6 parser Main" data-noexport="" id="concept-ipv6-parser-main">Main<a class="self-link" href="#concept-ipv6-parser-main"></a></dfn>:
While <a data-link-type="dfn" href="#c">c</a> is not the <a data-link-type="dfn" href="#eof-code-point">EOF code point</a>, run these
substeps:
</p>
<ol>
<li>
<p>If <var>piece pointer</var> is eight, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>, return failure.
</p>
<li>
<p>If <a data-link-type="dfn" href="#c">c</a> is "<code>:</code>", run these inner
substeps:
</p>
<ol>
<li>
<p>If <var>compress pointer</var> is non-null, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>,
return failure.
</p>
<li>Increase <var>pointer</var> and <var>piece pointer</var> by one, set
<var>compress pointer</var> to <var>piece pointer</var>,
and then jump to <a data-link-type="dfn" href="#concept-ipv6-parser-main">Main</a>.
</ol>
<li>
<p>Let <var>value</var> and <var>length</var> be 0.
</p>
<li>
<p>While <var>length</var> is less than 4 and
<a data-link-type="dfn" href="#c">c</a> is an
<a data-link-type="dfn" href="#ascii-hex-digits">ASCII hex digit</a>, set
<var>value</var> to
<var>value</var> × 0x10 + <a data-link-type="dfn" href="#c">c</a> interpreted as hexadecimal number,
and increase <var>pointer</var> and <var>length</var> by one.
</p>
<li>
<p>Switching on <a data-link-type="dfn" href="#c">c</a>:
</p>
<dl class="switch">
<dt>"<code>.</code>"
<dd>
<ol>
<li>
<p>If <var>length</var> is 0, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>, return failure.
</p>
<li>
<p>Decrease <var>pointer</var> by <var>length</var>.
</p>
<li>
<p>Jump to <a data-link-type="dfn" href="#concept-ipv6-parser-ipv4">IPv4</a>.
</p>
</ol>
<dt>"<code>:</code>"
<dd>
<ol>
<li>
<p>Increase <var>pointer</var> by one.
</p>
<li>
<p>If <a data-link-type="dfn" href="#c">c</a> is the <a data-link-type="dfn" href="#eof-code-point">EOF code point</a>, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>,
return failure.
</p>
</ol>
<dt>Anything but the <a data-link-type="dfn" href="#eof-code-point">EOF code point</a>
<dd>
<p><a data-link-type="dfn" href="#syntax-violation">Syntax violation</a>, return failure.
</p>
</dl>
<li>
<p>Set <var>piece</var> to <var>value</var>.
</p>
<li>
<p>Increase <var>piece pointer</var> by one.
</p>
</ol>
<li>
<p>If <a data-link-type="dfn" href="#c">c</a> is the <a data-link-type="dfn" href="#eof-code-point">EOF code point</a>, jump to
<a data-link-type="dfn" href="#concept-ipv6-parser-finale">Finale</a>.
</p>
<li>
<p><dfn data-dfn-type="dfn" data-lt="IPv6 parser IPv4" data-noexport="" id="concept-ipv6-parser-ipv4">IPv4<a class="self-link" href="#concept-ipv6-parser-ipv4"></a></dfn>:
If <var>piece pointer</var> is greater than six, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>, return failure.
</p>
<li>
<p>Let <var>dots seen</var> be 0.
</p>
<li>
<p>While <a data-link-type="dfn" href="#c">c</a> is not the <a data-link-type="dfn" href="#eof-code-point">EOF code point</a>, run
these substeps:
</p>
<ol>
<li>
<p>Let <var>value</var> be null.
</p>
<li>
<p>If <a data-link-type="dfn" href="#c">c</a> is not an <a data-link-type="dfn" href="#ascii-digits">ASCII digit</a>, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>,
return failure.