/
url.html
2519 lines (2515 loc) · 221 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">
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
<meta content="#3c790a" name="theme-color">
<title>URL Standard</title>
<link href="https://resources.whatwg.org/standard.css" 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">
<style>/* style-syntax-highlighting */
pre.idl.highlight { color: #708090; }
.highlight:not(.idl) { background: hsl(24, 20%, 95%); }
code.highlight { padding: .1em; border-radius: .3em; }
pre.highlight, pre > code.highlight { display: block; padding: 1em; margin: .5em 0; overflow: auto; border-radius: 0; }
.highlight .c { color: #708090 } /* Comment */
.highlight .k { color: #990055 } /* Keyword */
.highlight .l { color: #000000 } /* Literal */
.highlight .n { color: #0077aa } /* Name */
.highlight .o { color: #999999 } /* Operator */
.highlight .p { color: #999999 } /* Punctuation */
.highlight .cm { color: #708090 } /* Comment.Multiline */
.highlight .cp { color: #708090 } /* Comment.Preproc */
.highlight .c1 { color: #708090 } /* Comment.Single */
.highlight .cs { color: #708090 } /* Comment.Special */
.highlight .kc { color: #990055 } /* Keyword.Constant */
.highlight .kd { color: #990055 } /* Keyword.Declaration */
.highlight .kn { color: #990055 } /* Keyword.Namespace */
.highlight .kp { color: #990055 } /* Keyword.Pseudo */
.highlight .kr { color: #990055 } /* Keyword.Reserved */
.highlight .kt { color: #990055 } /* Keyword.Type */
.highlight .ld { color: #000000 } /* Literal.Date */
.highlight .m { color: #000000 } /* Literal.Number */
.highlight .s { color: #a67f59 } /* Literal.String */
.highlight .na { color: #0077aa } /* Name.Attribute */
.highlight .nc { color: #0077aa } /* Name.Class */
.highlight .no { color: #0077aa } /* Name.Constant */
.highlight .nd { color: #0077aa } /* Name.Decorator */
.highlight .ni { color: #0077aa } /* Name.Entity */
.highlight .ne { color: #0077aa } /* Name.Exception */
.highlight .nf { color: #0077aa } /* Name.Function */
.highlight .nl { color: #0077aa } /* Name.Label */
.highlight .nn { color: #0077aa } /* Name.Namespace */
.highlight .py { color: #0077aa } /* Name.Property */
.highlight .nt { color: #669900 } /* Name.Tag */
.highlight .nv { color: #222222 } /* Name.Variable */
.highlight .ow { color: #999999 } /* Operator.Word */
.highlight .mb { color: #000000 } /* Literal.Number.Bin */
.highlight .mf { color: #000000 } /* Literal.Number.Float */
.highlight .mh { color: #000000 } /* Literal.Number.Hex */
.highlight .mi { color: #000000 } /* Literal.Number.Integer */
.highlight .mo { color: #000000 } /* Literal.Number.Oct */
.highlight .sb { color: #a67f59 } /* Literal.String.Backtick */
.highlight .sc { color: #a67f59 } /* Literal.String.Char */
.highlight .sd { color: #a67f59 } /* Literal.String.Doc */
.highlight .s2 { color: #a67f59 } /* Literal.String.Double */
.highlight .se { color: #a67f59 } /* Literal.String.Escape */
.highlight .sh { color: #a67f59 } /* Literal.String.Heredoc */
.highlight .si { color: #a67f59 } /* Literal.String.Interpol */
.highlight .sx { color: #a67f59 } /* Literal.String.Other */
.highlight .sr { color: #a67f59 } /* Literal.String.Regex */
.highlight .s1 { color: #a67f59 } /* Literal.String.Single */
.highlight .ss { color: #a67f59 } /* Literal.String.Symbol */
.highlight .vc { color: #0077aa } /* Name.Variable.Class */
.highlight .vg { color: #0077aa } /* Name.Variable.Global */
.highlight .vi { color: #0077aa } /* Name.Variable.Instance */
.highlight .il { color: #000000 } /* Literal.Number.Integer.Long */
</style>
<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>
<hgroup>
<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="2016-07-28">28 July 2016</time></span></h2>
</hgroup>
<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>
<dt>Translation (non-normative):
<dd><span><span title="Japanese"><a href="https://triple-underscore.github.io/URL-ja.html" hreflang="ja" lang="ja" rel="alternate">日本語</a></span></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>
<nav data-fill-with="table-of-contents" id="toc">
<h2 class="no-num no-toc no-ref" id="contents">Table of Contents</h2>
<ol class="toc" role="directory">
<li><a href="#goals"><span class="secno"></span> <span class="content">Goals</span></a>
<li>
<a href="#infrastructure"><span class="secno">1</span> <span class="content">Infrastructure</span></a>
<ol class="toc">
<li><a href="#parsers"><span class="secno">1.1</span> <span class="content">Parsers</span></a>
<li><a href="#percent-encoded-bytes"><span class="secno">1.2</span> <span class="content">Percent-encoded bytes</span></a>
</ol>
<li><a href="#security-considerations"><span class="secno">2</span> <span class="content">Security considerations</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>
<ol 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>
<li><a href="#host-equivalence"><span class="secno">3.5</span> <span class="content">Host equivalence</span></a>
</ol>
<li>
<a href="#urls"><span class="secno">4</span> <span class="content">URLs</span></a>
<ol 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>
<li><a href="#url-rendering"><span class="secno">4.6</span> <span class="content">URL rendering</span></a>
</ol>
<li>
<a href="#application/x-www-form-urlencoded"><span class="secno">5</span> <span class="content"><code>application/x-www-form-urlencoded</code></span></a>
<ol class="toc">
<li><a href="#urlencoded-parsing"><span class="secno">5.1</span> <span class="content"><code>application/x-www-form-urlencoded</code> parsing</span></a>
<li><a href="#urlencoded-serializing"><span class="secno">5.2</span> <span class="content"><code>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>
</ol>
<li>
<a href="#api"><span class="secno">6</span> <span class="content">API</span></a>
<ol 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-members"><span class="secno">6.3</span> <span class="content"><code class="idl"><span>URL</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>
</ol>
<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>
<ol 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>
</ol>
<li>
<a href="#references"><span class="secno"></span> <span class="content">References</span></a>
<ol 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>
</ol>
<li><a href="#idl-index"><span class="secno"></span> <span class="content">IDL Index</span></a>
</ol>
</nav>
<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="infrastructure"><span class="secno">1. </span><span class="content">Infrastructure</span><a class="self-link" href="#infrastructure"></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="tab-and-newline">tab and newline<a class="self-link" href="#tab-and-newline"></a></dfn> are code points U+0009, U+000A, and U+000D. </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="windows-drive-letter">Windows drive letter<a class="self-link" href="#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="normalized-windows-drive-letter">normalized Windows drive letter<a class="self-link" href="#normalized-windows-drive-letter"></a></dfn> is a <a data-link-type="dfn" href="#windows-drive-letter">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>
<h3 class="heading settled" data-level="1.2" id="percent-encoded-bytes"><span class="secno">1.2. </span><span class="content">Percent-encoded bytes</span><a class="self-link" href="#percent-encoded-bytes"></a></h3>
<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 data-link-type="dfn" href="https://encoding.spec.whatwg.org/#utf-8-decode-without-bom-or-fail">UTF-8 decode without BOM or fail</a> to return failure. </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 data-link-type="dfn" href="https://encoding.spec.whatwg.org/#utf-8-decode-without-bom">UTF-8 decode without BOM</a> when the <var>input</var> contains bytes that are not <a data-link-type="dfn" href="https://encoding.spec.whatwg.org/#ascii-byte">ASCII bytes</a> 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>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="2" id="security-considerations"><span class="secno">2. </span><span class="content">Security considerations</span><a class="self-link" href="#security-considerations"></a></h2>
<p>The security of a <a data-link-type="dfn" href="#concept-url">URL</a> is a function of its environment. Care is to be
taken when rendering, interpreting, and passing <a data-link-type="dfn" href="#concept-url">URLs</a> around. </p>
<p>When rendering and allocating new <a data-link-type="dfn" href="#concept-url">URLs</a> "spoofing" needs to be
considered. An attack whereby one <a data-link-type="dfn" href="#concept-host">host</a> or <a data-link-type="dfn" href="#concept-url">URL</a> can be
confused for another. E.g., consider how 1/l/I, m/rn/rri, 0/O, and а/a can all appear
eerily similar. Or worse, consider how U+202A and similar code points are invisible. <a data-link-type="biblio" href="#biblio-uts36">[UTS36]</a> </p>
<p>When passing a <a data-link-type="dfn" href="#concept-url">URL</a> from party <var>A</var> to <var>B</var>, both need to
carefully consider what is happening. <var>A</var> might end up leaking data it does not
want to leak. <var>B</var> might receive input it did not expect and take an action that
harms the user. In particular, <var>B</var> should never trust <var>A</var>, as at some
point <a data-link-type="dfn" href="#concept-url">URLs</a> from <var>A</var> can come from untrusted sources. </p>
<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 <a data-link-type="dfn" href="#ascii-digits">ASCII digits</a> per sequence, each representing a decimal
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
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>",
or
"<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 a <var>syntaxViolationFlag</var> pointer, 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>Set <var>syntaxViolationFlag</var>. </p>
<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>Set <var>syntaxViolationFlag</var>. </p>
<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,
and 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>syntaxViolationFlag</var> be unset. </p>
<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, set <var>syntaxViolationFlag</var> and remove the last item 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> using <var>syntaxViolationFlag</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 <var>syntaxViolationFlag</var> is set, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>. </p>
<li>
<p>If any item in <var>numbers</var> is greater than 255, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>. </p>
<li>
<p>If any but the last item in <var>numbers</var> is greater than 255, 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. </p>
<li>
<p>While <a data-link-type="dfn" href="#c">c</a> is an <a data-link-type="dfn" href="#ascii-digits">ASCII digit</a>, run these subsubsteps: </p>
<ol>
<li>
<p>Let <var>number</var> be <a data-link-type="dfn" href="#c">c</a> interpreted as decimal number. </p>
<li>
<p>If <var>value</var> is null, set <var>value</var> to <var>number</var>. </p>
<p>Otherwise, if <var>value</var> is 0, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>, return failure. </p>
<p>Otherwise, set <var>value</var> to <var>value</var> × 10 + <var>number</var>. </p>
<li>
<p>Increase <var>pointer</var> by one. </p>
<li>
<p>If <var>value</var> is greater than 255, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>,
return failure. </p>
</ol>
<li>
<p>If <var>dots seen</var> is less than 3 and <a data-link-type="dfn" href="#c">c</a> is not a "<code>.</code>", <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>, return failure. </p>
<li>
<p>Set <var>piece</var> to <var>piece</var> × 0x100 + <var>value</var>. </p>
<li>
<p>If <var>dots seen</var> is 1 or 3, increase <var>piece pointer</var> by one. </p>
<li>
<p>If <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>, increase <var>pointer</var> by
one. </p>
<li>
<p>If <var>dots seen</var> is 3 and <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>, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>, return failure. </p>
<li>
<p>Increase <var>dots seen</var> by one. </p>
</ol>
<li>
<p><dfn data-dfn-type="dfn" data-lt="IPv6 parser Finale" data-noexport="" id="concept-ipv6-parser-finale">Finale<a class="self-link" href="#concept-ipv6-parser-finale"></a></dfn>:
If <var>compress pointer</var> is non-null, run these substeps: </p>
<ol>
<li>
<p>Let <var>swaps</var> be <var>piece pointer</var> − <var>compress pointer</var>. </p>
<li>
<p>Set <var>piece pointer</var> to seven. </p>
<li>
<p>While <var>piece pointer</var> is not zero and <var>swaps</var> is
greater than zero, swap <var>piece</var> with the <a data-link-type="dfn" href="#concept-ipv6-piece">piece</a> at pointer <var>compress pointer</var> + <var>swaps</var> − 1, and then
decrease both <var>piece pointer</var> and <var>swaps</var> by one. </p>
</ol>
<li>
<p>Otherwise, if <var>compress pointer</var> is null and <var>piece pointer</var> is
not eight, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>, return failure. </p>
<li>
<p>Return <var>address</var>. </p>
</ol>
<p class="note no-backref" role="note">To be clear, <a data-link-type="dfn" href="#concept-ipv6-parser-main">Main</a>, <a data-link-type="dfn" href="#concept-ipv6-parser-ipv4">IPv4</a>, and <a data-link-type="dfn" href="#concept-ipv6-parser-finale">Finale</a> are simple markers.
They serve no purpose other than being a location the algorithm can jump to. </p>
<h3 class="heading settled" data-level="3.4" id="host-serializing"><span class="secno">3.4. </span><span class="content">Host serializing</span><a class="self-link" href="#host-serializing"></a></h3>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="concept-host-serializer">host serializer<a class="self-link" href="#concept-host-serializer"></a></dfn> takes a <a data-link-type="dfn" href="#concept-host">host</a> <var>host</var> and then runs these steps: </p>
<ol>
<li>
<p>If <var>host</var> is an <a data-link-type="dfn" href="#concept-ipv4">IPv4 address</a>, return the result of
running the <a data-link-type="dfn" href="#concept-ipv4-serializer">IPv4 serializer</a> on <var>host</var>. </p>
<li>
<p>Otherwise, if <var>host</var> is an <a data-link-type="dfn" href="#concept-ipv6">IPv6 address</a>, return
"<code>[</code>", followed by the result of running the <a data-link-type="dfn" href="#concept-ipv6-serializer">IPv6 serializer</a> on <var>host</var>,
followed by "<code>]</code>". </p>
<li>
<p>Otherwise, <var>host</var> is a <a data-link-type="dfn" href="#concept-domain">domain</a>, return <var>host</var>. </p>
</ol>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="concept-ipv4-serializer">IPv4 serializer<a class="self-link" href="#concept-ipv4-serializer"></a></dfn> takes an <a data-link-type="dfn" href="#concept-ipv4">IPv4 address</a> <var>address</var> and then runs these steps:</p>
<ol>
<li>
<p>Let <var>output</var> be the empty string. </p>
<li>
<p>Let <var>n</var> be the value of <var>address</var>. </p>
<li>
<p>Repeat four times: </p>
<ol>
<li>
<p>Prepend <var>n</var> % 256, <a data-link-type="dfn" href="#serialize-an-integer">serialized</a>, to <var>output</var>. </p>
<li>
<p>Unless this is the fourth time, prepend "<code>.</code>" to <var>output</var>. </p>
<li>
<p>Set <var>n</var> to floor(<var>n</var> / 256). </p>
</ol>
<li>
<p>Return <var>output</var>. </p>
</ol>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="concept-ipv6-serializer">IPv6 serializer<a class="self-link" href="#concept-ipv6-serializer"></a></dfn> takes an <a data-link-type="dfn" href="#concept-ipv6">IPv6 address</a> <var>address</var> and then runs these steps: </p>
<ol>
<li>
<p>Let <var>output</var> be the empty string. </p>
<li>
<p>Let <var>compress pointer</var> be a pointer to the first <a data-link-type="dfn" href="#concept-ipv6-piece">16-bit piece</a> in the first longest
sequences of <var>address</var>’s <a data-link-type="dfn" href="#concept-ipv6-piece">16-bit pieces</a> that are 0. </p>
<p class="example" id="example-e2b3492e"><a class="self-link" href="#example-e2b3492e"></a>In <code>0:f:0:0:f:f:0:0</code> it would point to
the second 0. </p>
<li>
<p>If there is no sequence of <var>address</var>’s <a data-link-type="dfn" href="#concept-ipv6-piece">16-bit pieces</a> that are 0 longer than
one, set <var>compress pointer</var> to null. </p>
<li>
<p>For each <var>piece</var> in <var>address</var>’s <a data-link-type="dfn" href="#concept-ipv6-piece">pieces</a>, run these substeps: </p>
<ol>
<li>
<p>If <var>compress pointer</var> points to <var>piece</var>, append "<code>::</code>" to <var>output</var> if <var>piece</var> is <var>address</var>’s first <a data-link-type="dfn" href="#concept-ipv6-piece">piece</a> and append
"<code>:</code>" otherwise, and then run these substeps again with all
subsequent <a data-link-type="dfn" href="#concept-ipv6-piece">pieces</a> in <var>address</var>’s <a data-link-type="dfn" href="#concept-ipv6-piece">pieces</a> that are 0 skipped or go the next step in the overall set of steps if
that leaves no <a data-link-type="dfn" href="#concept-ipv6-piece">pieces</a>. </p>
<li>
<p>Append <var>piece</var>, represented as the shortest
possible lowercase hexadecimal number, to <var>output</var>. </p>
<li>
<p>If <var>piece</var> is not <var>address</var>’s last <a data-link-type="dfn" href="#concept-ipv6-piece">piece</a>,
append "<code>:</code>" to <var>output</var>. </p>
</ol>
<li>
<p>Return <var>output</var>. </p>
</ol>
<p class="note" role="note">This algorithm requires the recommendation from
A Recommendation for IPv6 Address Text Representation. <a data-link-type="biblio" href="#biblio-rfc5952">[RFC5952]</a> </p>
<h3 class="heading settled" data-level="3.5" id="host-equivalence"><span class="secno">3.5. </span><span class="content">Host equivalence</span><a class="self-link" href="#host-equivalence"></a></h3>
<p>To determine whether a <a data-link-type="dfn" href="#concept-host">host</a> <var>A</var> <dfn data-dfn-for="host" data-dfn-type="dfn" data-export="" id="concept-host-equals">equals<a class="self-link" href="#concept-host-equals"></a></dfn> <var>B</var>, return true if <var>A</var> is <var>B</var>, and false otherwise.</p>
<p class="XXX">Certificate comparison requires a host equivalence check that ignores the
trailing dot of a domain (if any). However, those hosts have also various other facets
enforced, such as DNS length, that are not enforced here, as URLs do not enforce them. If
anyone has a good suggestion for how to bring these two closer together, or what a good
unified model would be, please file an issue. </p>
<h2 class="heading settled" data-level="4" id="urls"><span class="secno">4. </span><span class="content">URLs</span><a class="self-link" href="#urls"></a></h2>
<p>A <dfn data-dfn-for="url" data-dfn-type="dfn" data-export="" data-lt="URL|URL record" id="concept-url">URL<a class="self-link" href="#concept-url"></a></dfn> is a universal
identifier. To disambiguate from a <a data-link-type="dfn" href="#syntax-url">URL string</a> it can also be referred to as a <a data-link-type="dfn" href="#concept-url">URL record</a>. </p>
<p>A <a data-link-type="dfn" href="#concept-url">URL</a>’s <dfn data-dfn-for="url" data-dfn-type="dfn" data-export="" id="concept-url-scheme">scheme<a class="self-link" href="#concept-url-scheme"></a></dfn> is an <a data-link-type="dfn" href="#ascii-string">ASCII string</a> that identifies the type of <a data-link-type="dfn" href="#concept-url">URL</a> and can be used to
dispatch a <a data-link-type="dfn" href="#concept-url">URL</a> for further processing after <a data-link-type="dfn" href="#concept-url-parser">parsing</a>.
It is initially the empty string. </p>
<p>A <a data-link-type="dfn" href="#concept-url">URL</a>’s <dfn data-dfn-for="url" data-dfn-type="dfn" data-export="" id="concept-url-username">username<a class="self-link" href="#concept-url-username"></a></dfn> is
an <a data-link-type="dfn" href="#ascii-string">ASCII string</a> identifying a user. It is initially the empty string. </p>
<p>A <a data-link-type="dfn" href="#concept-url">URL</a>’s <dfn data-dfn-for="url" data-dfn-type="dfn" data-export="" id="concept-url-password">password<a class="self-link" href="#concept-url-password"></a></dfn> is
either null or an <a data-link-type="dfn" href="#ascii-string">ASCII string</a> identifying a user’s credentials. It is initially
null. </p>
<p>A <a data-link-type="dfn" href="#concept-url">URL</a>’s <dfn data-dfn-for="url" data-dfn-type="dfn" data-export="" id="concept-url-host">host<a class="self-link" href="#concept-url-host"></a></dfn> is either
null or a <a data-link-type="dfn" href="#concept-host">host</a>. It is initially null. </p>
<p>A <a data-link-type="dfn" href="#concept-url">URL</a>’s <dfn data-dfn-for="url" data-dfn-type="dfn" data-export="" id="concept-url-port">port<a class="self-link" href="#concept-url-port"></a></dfn> is either
null or a 16-bit unsigned integer that identifies a networking port. It is initially null. </p>
<p>A <a data-link-type="dfn" href="#concept-url">URL</a>’s <dfn data-dfn-for="url" data-dfn-type="dfn" data-export="" id="concept-url-path">path<a class="self-link" href="#concept-url-path"></a></dfn> is a list of
zero or more <a data-link-type="dfn" href="#ascii-string">ASCII string</a> holding data, usually identifying a location in
hierarchical form. It is initially the empty list. </p>
<p>A <a data-link-type="dfn" href="#concept-url">URL</a>’s <dfn data-dfn-for="url" data-dfn-type="dfn" data-export="" id="concept-url-query">query<a class="self-link" href="#concept-url-query"></a></dfn> is either
null or an <a data-link-type="dfn" href="#ascii-string">ASCII string</a> holding data. It is initially null. </p>
<p>A <a data-link-type="dfn" href="#concept-url">URL</a>’s <dfn data-dfn-for="url" data-dfn-type="dfn" data-export="" id="concept-url-fragment">fragment<a class="self-link" href="#concept-url-fragment"></a></dfn> is
either null or a string holding data that can be used for further processing on the
resource the <a data-link-type="dfn" href="#concept-url">URL</a>’s other components identify. It is initially null. </p>
<p class="note no-backref" role="note">This is not an <a data-link-type="dfn" href="#ascii-string">ASCII string</a> on purpose. </p>
<p id="non-relative-flag">A <a data-link-type="dfn" href="#concept-url">URL</a> also has an associated <dfn data-dfn-for="url" data-dfn-type="dfn" data-export="" id="url-cannot-be-a-base-url-flag">cannot-be-a-base-URL flag<a class="self-link" href="#url-cannot-be-a-base-url-flag"></a></dfn>. It is initially unset. </p>
<p>A <a data-link-type="dfn" href="#concept-url">URL</a> also has an associated <dfn data-dfn-for="url" data-dfn-type="dfn" data-export="" id="concept-url-object">object<a class="self-link" href="#concept-url-object"></a></dfn> that is null, a <code class="idl"><a data-link-type="idl" href="https://w3c.github.io/FileAPI/#dfn-Blob">Blob</a></code> object, a <code class="idl"><a data-link-type="idl" href="https://w3c.github.io/media-source/#idl-def-MediaSource">MediaSource</a></code> object, or a <code class="idl"><a data-link-type="idl" href="https://www.w3.org/TR/mediacapture-streams/#idl-def-MediaStream">MediaStream</a></code> object. It is initially null. <a data-link-type="biblio" href="#biblio-fileapi">[FILEAPI]</a> <a data-link-type="biblio" href="#biblio-media-source">[MEDIA-SOURCE]</a> <a data-link-type="biblio" href="#biblio-mediacapture-streams">[MEDIACAPTURE-STREAMS]</a> </p>
<p class="note no-backref" role="note">At this point this is used primarily to support
"<code>blob</code>" <a data-link-type="dfn" href="#concept-url">URLs</a>, but others can be added going forward, hence
"object". </p>
<hr>
<p>A <dfn data-dfn-type="dfn" data-export="" id="special-scheme">special scheme<a class="self-link" href="#special-scheme"></a></dfn> is a <a data-link-type="dfn" href="#concept-url-scheme">scheme</a> listed in the first column of
the following table. A <dfn data-dfn-type="dfn" data-noexport="" id="default-port">default port<a class="self-link" href="#default-port"></a></dfn> is a <a data-link-type="dfn" href="#special-scheme">special scheme</a>’s optional
corresponding <a data-link-type="dfn" href="#concept-url-port">port</a> and is listed in the second column on the same row. </p>
<table>
<tbody>
<tr>
<th><a data-link-type="dfn" href="#concept-url-scheme">scheme</a>
<th><a data-link-type="dfn" href="#concept-url-port">port</a>
<tr>
<td>"<code>ftp</code>"
<td>21
<tr>
<td>"<code>file</code>"
<td>
<tr>
<td>"<code>gopher</code>"
<td>70
<tr>
<td>"<code>http</code>"
<td>80
<tr>
<td>"<code>https</code>"
<td>443
<tr>
<td>"<code>ws</code>"
<td>80
<tr>
<td>"<code>wss</code>"
<td>443
</table>
<p>A <a data-link-type="dfn" href="#concept-url">URL</a> <dfn data-dfn-type="dfn" data-export="" id="is-special">is special<a class="self-link" href="#is-special"></a></dfn> if its <a data-link-type="dfn" href="#concept-url-scheme">scheme</a> is a <a data-link-type="dfn" href="#special-scheme">special scheme</a>. </p>
<p>A <dfn data-dfn-type="dfn" data-export="" id="local-scheme">local scheme<a class="self-link" href="#local-scheme"></a></dfn> is a <a data-link-type="dfn" href="#concept-url-scheme">scheme</a> that is "<code>about</code>",
"<code>blob</code>", "<code>data</code>", or "<code>filesystem</code>". </p>
<p>A <a data-link-type="dfn" href="#concept-url">URL</a> <dfn data-dfn-type="dfn" data-noexport="" id="is-local">is local<a class="self-link" href="#is-local"></a></dfn> if its <a data-link-type="dfn" href="#concept-url-scheme">scheme</a> is a <a data-link-type="dfn" href="#local-scheme">local scheme</a>. </p>
<p class="note" role="note">This definition is used externally. E.g., by the Fetch Standard and
Referrer Policy. <a data-link-type="biblio" href="#biblio-fetch">[FETCH]</a> <a data-link-type="biblio" href="#biblio-referrer-policy">[REFERRER-POLICY]</a> </p>
<p>An <dfn data-dfn-type="dfn" data-export="" id="http-scheme">HTTP(S) scheme<a class="self-link" href="#http-scheme"></a></dfn> is a <a data-link-type="dfn" href="#concept-url-scheme">scheme</a> that is
"<code>http</code>" or "<code>https</code>". </p>
<p>A <dfn data-dfn-type="dfn" data-export="" id="network-scheme">network scheme<a class="self-link" href="#network-scheme"></a></dfn> is a <a data-link-type="dfn" href="#concept-url-scheme">scheme</a> that is "<code>ftp</code>" or an <span>HTTP(S) scheme</span>. </p>
<p>A <dfn data-dfn-type="dfn" data-export="" id="fetch-scheme">fetch scheme<a class="self-link" href="#fetch-scheme"></a></dfn> is a <a data-link-type="dfn" href="#concept-url-scheme">scheme</a> that is "<code>about</code>",
"<code>blob</code>", "<code>data</code>", "<code>file</code>", "<code>filesystem</code>", or a <span>network scheme</span>. </p>
<p class="note no-backref" role="note"><a data-link-type="dfn" href="#http-scheme">HTTP(S) scheme</a>, <a data-link-type="dfn" href="#network-scheme">network scheme</a>, and <span>fetch scheme</span> are used by HTML. <a data-link-type="biblio" href="#biblio-html">[HTML]</a> </p>
<p>A <a data-link-type="dfn" href="#concept-url">URL</a> <dfn data-dfn-type="dfn" data-lt="include credentials" data-noexport="" id="include-credentials">includes credentials<a class="self-link" href="#include-credentials"></a></dfn> if either
its <a data-link-type="dfn" href="#concept-url-username">username</a> is not the empty string or its <a data-link-type="dfn" href="#concept-url-password">password</a> is
non-null. </p>
<p>A <a data-link-type="dfn" href="#concept-url">URL</a> can be designated as <dfn data-dfn-type="dfn" data-noexport="" id="concept-base-url">base URL<a class="self-link" href="#concept-base-url"></a></dfn>. </p>
<p class="note no-backref" role="note">A <a data-link-type="dfn" href="#concept-base-url">base URL</a> is useful for the <a data-link-type="dfn" href="#concept-url-parser">URL parser</a> when the
input might be a <a data-link-type="dfn" href="#syntax-url-relative">relative URL</a>. </p>
<hr>
<p>To <dfn data-dfn-type="dfn" data-local-lt="pop" data-noexport="" id="pop-a-urls-path">pop a <var>url</var>’s path<a class="self-link" href="#pop-a-urls-path"></a></dfn>, if <var>url</var>’s <a data-link-type="dfn" href="#concept-url-scheme">scheme</a> is not "<code>file</code>" or <var>url</var>’s <a data-link-type="dfn" href="#concept-url-path">path</a> does not contain a single string that is a <a data-link-type="dfn" href="#normalized-windows-drive-letter">normalized Windows drive letter</a>, remove <var>url</var>’s <a data-link-type="dfn" href="#concept-url-path">path</a>’s
last string, if any. </p>
<h3 class="heading settled" data-level="4.1" id="url-syntax"><span class="secno">4.1. </span><span class="content">URL syntax</span><a class="self-link" href="#url-syntax"></a></h3>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" data-lt="URL|URL string" id="syntax-url">URL<a class="self-link" href="#syntax-url"></a></dfn> must be either
a <a data-link-type="dfn" href="#syntax-url-relative-with-fragment">relative URL with fragment</a> or an <a data-link-type="dfn" href="#syntax-url-absolute-with-fragment">absolute URL with fragment</a>. To
disambiguate from a <a data-link-type="dfn" href="#concept-url">URL record</a> it can also be referred to as a <a data-link-type="dfn" href="#syntax-url">URL string</a>. </p>
<p>An <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-absolute-with-fragment">absolute URL with fragment<a class="self-link" href="#syntax-url-absolute-with-fragment"></a></dfn> must be an <a data-link-type="dfn" href="#syntax-url-absolute">absolute URL</a>, optionally followed by "<code>#</code>" and a <a data-link-type="dfn" href="#syntax-url-fragment">fragment</a>. </p>
<p>An <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-absolute">absolute URL<a class="self-link" href="#syntax-url-absolute"></a></dfn> must be one of
the following </p>
<ul class="brief">
<li>
<p>a <a data-link-type="dfn" href="#syntax-url-scheme">scheme</a> that is an <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a> match for a <a data-link-type="dfn" href="#special-scheme">special scheme</a> and not an <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a> match
for "<code>file</code>", followed by "<code>:</code>" and a <a data-link-type="dfn" href="#syntax-url-scheme-relative">scheme-relative URL</a> </p>
<li>
<p>a <a data-link-type="dfn" href="#syntax-url-scheme">scheme</a> that is <em>not</em> an <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a> match for a <a data-link-type="dfn" href="#special-scheme">special scheme</a>, followed by
"<code>:</code>" and a <a data-link-type="dfn" href="#syntax-url-relative">relative URL</a> </p>
<li>
<p>a <a data-link-type="dfn" href="#syntax-url-scheme">scheme</a> that is an <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a> match for "<code>file</code>", followed by "<code>:</code>" and a <a data-link-type="dfn" href="#syntax-url-file-scheme-relative">scheme-relative file URL</a> </p>
</ul>
<p>any optionally followed by "<code>?</code>" and a <a data-link-type="dfn" href="#syntax-url-query">query</a>. </p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-scheme">scheme<a class="self-link" href="#syntax-url-scheme"></a></dfn> must be one <a data-link-type="dfn" href="#ascii-alpha">ASCII alpha</a>, followed by zero or more of <a data-link-type="dfn" href="#ascii-alphanumeric">ASCII alphanumeric</a>,
"<code>+</code>", "<code>-</code>", and "<code>.</code>". <a data-link-type="dfn" href="#syntax-url-scheme">Schemes</a> should be registered in the <cite>IANA URI [sic] Schemes</cite> registry. <a data-link-type="biblio" href="#biblio-iana-uri-schemes">[IANA-URI-SCHEMES]</a> <a data-link-type="biblio" href="#biblio-rfc7595">[RFC7595]</a> </p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-relative-with-fragment">relative URL with fragment<a class="self-link" href="#syntax-url-relative-with-fragment"></a></dfn> must be a <a data-link-type="dfn" href="#syntax-url-relative">relative URL</a>, optionally followed by "<code>#</code>" and a <a data-link-type="dfn" href="#syntax-url-fragment">fragment</a>. </p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-relative">relative URL<a class="self-link" href="#syntax-url-relative"></a></dfn> must be one of
the following, switching on <a data-link-type="dfn" href="#concept-base-url">base URL</a>’s <a data-link-type="dfn" href="#concept-url-scheme">scheme</a>: </p>
<dl class="switch">
<dt>Not "<code>file</code>"
<dd>
<p>a <a data-link-type="dfn" href="#syntax-url-scheme-relative">scheme-relative URL</a> </p>
<dd>
<p>a <a data-link-type="dfn" href="#syntax-url-path-absolute">path-absolute URL</a> </p>
<dd>
<p>a <a data-link-type="dfn" href="#syntax-url-path-relative-scheme-less">path-relative scheme-less URL</a> </p>
<dt>"<code>file</code>"
<dd>
<p>a <a data-link-type="dfn" href="#syntax-url-file-scheme-relative">scheme-relative file URL</a> </p>
<dd>
<p>a <a data-link-type="dfn" href="#syntax-url-path-absolute">path-absolute URL</a> if <a data-link-type="dfn" href="#concept-base-url">base URL</a>’s <a data-link-type="dfn" href="#concept-url-host">host</a> is null </p>
<dd>
<p>a <a data-link-type="dfn" href="#syntax-url-file-path-absolute">path-absolute non-Windows-file URL</a> if <a data-link-type="dfn" href="#concept-base-url">base URL</a>’s <a data-link-type="dfn" href="#concept-url-host">host</a> is non-null </p>
<dd>
<p>a <a data-link-type="dfn" href="#syntax-url-path-relative-scheme-less">path-relative scheme-less URL</a> </p>
</dl>
<p>any optionally followed by "<code>?</code>" and a <a data-link-type="dfn" href="#syntax-url-query">query</a>. </p>
<p class="note no-backref" role="note">A non-null <a data-link-type="dfn" href="#concept-base-url">base URL</a> is necessary when <a data-link-type="dfn" href="#concept-url-parser">parsing</a> a <a data-link-type="dfn" href="#syntax-url-relative">relative URL</a>. </p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-scheme-relative">scheme-relative URL<a class="self-link" href="#syntax-url-scheme-relative"></a></dfn> must be "<code>//</code>", followed by a <a data-link-type="dfn" href="#syntax-host">host</a>, optionally followed
by "<code>:</code>" and a <a data-link-type="dfn" href="#syntax-url-port">port</a>, optionally followed by a <a data-link-type="dfn" href="#syntax-url-path-absolute">path-absolute URL</a>. </p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-port">port<a class="self-link" href="#syntax-url-port"></a></dfn> must be zero or more <a data-link-type="dfn" href="#ascii-digits">ASCII digits</a>. </p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-file-scheme-relative">scheme-relative file URL<a class="self-link" href="#syntax-url-file-scheme-relative"></a></dfn> must be "<code>//</code>", followed by one of the following </p>
<ul class="brief">
<li>
<p>a <a data-link-type="dfn" href="#syntax-host">host</a>, optionally followed by a <a data-link-type="dfn" href="#syntax-url-file-path-absolute">path-absolute non-Windows-file URL</a> </p>
<li>
<p>a <a data-link-type="dfn" href="#syntax-url-path-absolute">path-absolute URL</a>. </p>
</ul>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-path-absolute">path-absolute URL<a class="self-link" href="#syntax-url-path-absolute"></a></dfn> must be
"<code>/</code>" followed by a <a data-link-type="dfn" href="#syntax-url-path-relative">path-relative URL</a>. </p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-file-path-absolute">path-absolute non-Windows-file URL<a class="self-link" href="#syntax-url-file-path-absolute"></a></dfn> must be a <a data-link-type="dfn" href="#syntax-url-path-absolute">path-absolute URL</a> that does not start with "<code>/</code>", followed by
a <a data-link-type="dfn" href="#windows-drive-letter">Windows drive letter</a>, followed by "<code>/</code>". </p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-path-relative">path-relative URL<a class="self-link" href="#syntax-url-path-relative"></a></dfn> must be
zero or more <a data-link-type="dfn" href="#syntax-url-path-segment">path segments</a>, separated from each other by "<code>/</code>", and not
start with "<code>/</code>". </p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-path-relative-scheme-less">path-relative scheme-less URL<a class="self-link" href="#syntax-url-path-relative-scheme-less"></a></dfn> must be a <a data-link-type="dfn" href="#syntax-url-path-relative">path-relative URL</a> that does not start with a <a data-link-type="dfn" href="#syntax-url-scheme">scheme</a> and "<code>:</code>". </p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-path-segment">path segment<a class="self-link" href="#syntax-url-path-segment"></a></dfn> must be one
of the following </p>
<ul class="brief">
<li>
<p>zero or more <a data-link-type="dfn" href="#url-units">URL units</a>, excluding "<code>/</code>" and "<code>?</code>",
that together are not a <a data-link-type="dfn" href="#syntax-url-path-segment-dot">single-dot path segment</a> or a <a data-link-type="dfn" href="#syntax-url-path-segment-dotdot">double-dot path segment</a>. </p>
<li>
<p>a <a data-link-type="dfn" href="#syntax-url-path-segment-dot">single-dot path segment</a> </p>
<li>
<p>a <a data-link-type="dfn" href="#syntax-url-path-segment-dotdot">double-dot path segment</a>. </p>
</ul>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-path-segment-dot">single-dot path segment<a class="self-link" href="#syntax-url-path-segment-dot"></a></dfn> must be "<code>.</code>" or an <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a> match for
"<code>%2e</code>". </p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-path-segment-dotdot">double-dot path segment<a class="self-link" href="#syntax-url-path-segment-dotdot"></a></dfn> must be "<code>..</code>" or an <a data-link-type="dfn" href="https://dom.spec.whatwg.org/#ascii-case-insensitive">ASCII case-insensitive</a> match for
"<code>.%2e</code>", "<code>%2e.</code>", or "<code>%2e%2e</code>". </p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-query">query<a class="self-link" href="#syntax-url-query"></a></dfn> must be zero or more <a data-link-type="dfn" href="#url-units">URL units</a>. </p>
<p>A <dfn data-dfn-for="urlsyntax" data-dfn-type="dfn" data-export="" id="syntax-url-fragment">fragment<a class="self-link" href="#syntax-url-fragment"></a></dfn> must be zero or more <a data-link-type="dfn" href="#url-units">URL units</a>. </p>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="url-code-points">URL code points<a class="self-link" href="#url-code-points"></a></dfn> are <a data-link-type="dfn" href="#ascii-alphanumeric">ASCII alphanumeric</a>,
"<code>!</code>",
"<code>$</code>",
"<code>&</code>",
"<code>'</code>",
"<code>(</code>",
"<code>)</code>",
"<code>*</code>",
"<code>+</code>",
"<code>,</code>",
"<code>-</code>",
"<code>.</code>",
"<code>/</code>",
"<code>:</code>",
"<code>;</code>",
"<code>=</code>",
"<code>?</code>",
"<code>@</code>",
"<code>_</code>",
"<code>~</code>",
and code points in the ranges
U+00A0 to U+D7FF,
U+E000 to
U+FDCF,
U+FDF0 to U+FFFD,
U+10000 to U+1FFFD,
U+20000 to U+2FFFD,
U+30000 to U+3FFFD,
U+40000 to U+4FFFD,
U+50000 to U+5FFFD,
U+60000 to U+6FFFD,
U+70000 to U+7FFFD,
U+80000 to U+8FFFD,
U+90000 to U+9FFFD,
U+A0000 to U+AFFFD,
U+B0000 to U+BFFFD,
U+C0000 to U+CFFFD,
U+D0000 to U+DFFFD,
U+E0000 to U+EFFFD,
U+F0000 to U+FFFFD,
U+100000 to U+10FFFD. </p>
<p class="note" role="note">Code points higher than U+009F will be converted to <a data-link-type="dfn" href="#percent-encoded-byte">percent-encoded bytes</a> by the <a data-link-type="dfn" href="#concept-url-parser">URL parser</a>, except for code points appearing in <a data-link-type="dfn" href="#concept-url-fragment">fragments</a>. </p>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="url-units">URL units<a class="self-link" href="#url-units"></a></dfn> are <a data-link-type="dfn" href="#url-code-points">URL code points</a> and <a data-link-type="dfn" href="#percent-encoded-byte">percent-encoded bytes</a>. </p>
<p class="note" role="note"><a data-link-type="dfn" href="#percent-encoded-byte">Percent-encoded bytes</a> can be used to encode code points that are not <a data-link-type="dfn" href="#url-code-points">URL code points</a> or are excluded from a syntax production. </p>
<hr>
<p class="note no-backref" role="note">There is no conforming way to express a <a data-link-type="dfn" href="#concept-url-username">username</a> or <a data-link-type="dfn" href="#concept-url-password">password</a> of a <a data-link-type="dfn" href="#concept-url">URL record</a> within a <a data-link-type="dfn" href="#syntax-url">URL string</a>. </p>
<h3 class="heading settled" data-level="4.2" id="url-parsing"><span class="secno">4.2. </span><span class="content">URL parsing</span><a class="self-link" href="#url-parsing"></a></h3>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="concept-url-parser">URL parser<a class="self-link" href="#concept-url-parser"></a></dfn> takes a string <var>input</var>, with an optional <a data-link-type="dfn" href="#concept-base-url">base URL</a> <var>base</var> and an optional <a data-link-type="dfn" href="https://encoding.spec.whatwg.org/#encoding">encoding</a> <var>encoding override</var>, and then runs these steps: </p>
<p class="note no-backref" role="note">Non-web-browser implementations only need to implement the <a data-link-type="dfn" href="#concept-basic-url-parser">basic URL parser</a>. </p>
<ol>
<li>
<p>Let <var>url</var> be the result of running the <a data-link-type="dfn" href="#concept-basic-url-parser">basic URL parser</a> on <var>input</var> with <var>base</var>, and <var>encoding override</var> as provided. </p>
<li>
<p>If <var>url</var> is failure, return failure. </p>
<li>
<p>If <var>url</var>’s <a data-link-type="dfn" href="#concept-url-scheme">scheme</a> is not
"<code>blob</code>", return <var>url</var>. </p>
<li>
<p>If the first string in <var>url</var>’s <a data-link-type="dfn" href="#concept-url-path">path</a> is not in the <a data-link-type="dfn" href="https://w3c.github.io/FileAPI/#BlobURLStore">blob URL store</a>, return <var>url</var>. <a data-link-type="biblio" href="#biblio-fileapi">[FILEAPI]</a> </p>
<li>
<p>Set <var>url</var>’s <a data-link-type="dfn" href="#concept-url-object">object</a> to a <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/infrastructure.html#structured-clone">StructuredClone</a> of the
entry in the <a data-link-type="dfn" href="https://w3c.github.io/FileAPI/#BlobURLStore">blob URL store</a> corresponding to the first string in <var>url</var>’s <a data-link-type="dfn" href="#concept-url-path">path</a>. <a data-link-type="biblio" href="#biblio-html">[HTML]</a> </p>
<li>
<p>Return <var>url</var>. </p>
</ol>
<hr>
<p>The <dfn data-dfn-type="dfn" data-noexport="" id="concept-basic-url-parser">basic URL parser<a class="self-link" href="#concept-basic-url-parser"></a></dfn> takes a string <var>input</var>, optionally with a <a data-link-type="dfn" href="#concept-base-url">base URL</a> <var>base</var>,
optionally with an <a data-link-type="dfn" href="https://encoding.spec.whatwg.org/#encoding">encoding</a> <var>encoding override</var>, optionally with an <a data-link-type="dfn" href="#concept-url">URL</a> <var>url</var> and a state override <var>state override</var>, and then runs these steps: </p>
<div class="note no-backref" role="note">
<p>The <var>encoding override</var> argument is a legacy concept only relevant for
HTML. The <var>url</var> and <var>state override</var> arguments are only for use by various APIs. <a data-link-type="biblio" href="#biblio-html">[HTML]</a> </p>
<p>When the <var>url</var> and <var>state override</var> arguments are not passed, the <a data-link-type="dfn" href="#concept-basic-url-parser">basic URL parser</a> returns either a new <a data-link-type="dfn" href="#concept-url">URL</a> or failure. If they are
passed, the algorithm simply modifies the passed <var>url</var> and can terminate without
returning anything. </p>
</div>
<ol>
<li>
<p>If <var>url</var> is not given: </p>
<ol>
<li>
<p>Set <var>url</var> to a new <a data-link-type="dfn" href="#concept-url">URL</a>. </p>
<li>
<p>If <var>input</var> contains any leading or trailing <a data-link-type="dfn" href="#c0-controls-and-space">C0 controls and space</a>, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>. </p>
<li>
<p>Remove any leading and trailing <a data-link-type="dfn" href="#c0-controls-and-space">C0 controls and space</a> from <var>input</var>. </p>
</ol>
<li>
<p>If <var>input</var> contains any <a data-link-type="dfn" href="#tab-and-newline">tab and newline</a>, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>. </p>
<li>
<p>Remove all <a data-link-type="dfn" href="#tab-and-newline">tab and newline</a> from <var>input</var>. </p>
<li>
<p>Let <var>state</var> be <var>state override</var> if given, or <a data-link-type="dfn" href="#scheme-start-state">scheme start state</a> otherwise. </p>
<li>
<p>If <var>base</var> is not given, set it to null. </p>
<li>
<p>Let <var>encoding</var> be <a data-link-type="dfn" href="https://encoding.spec.whatwg.org/#utf-8">UTF-8</a>. </p>
<li>
<p>If <var>encoding override</var> is given, set <var>encoding</var> to the result of <a data-link-type="dfn" href="https://encoding.spec.whatwg.org/#get-an-output-encoding">getting an output encoding</a> from <var>encoding override</var>. </p>
<li>
<p>Let <var>buffer</var> be the empty string. </p>
<li>
<p>Let the <var>@ flag</var> and the <var>[] flag</var> be
unset. </p>
<li>
<p>Let <var>pointer</var> be a pointer to first code point in <var>input</var>. </p>
<li>
<p>Keep running the following state machine by switching on <var>state</var>. If after a run <var>pointer</var> points to <a data-link-type="dfn" href="#eof-code-point">EOF code point</a>, go to the next step. Otherwise, increase <var>pointer</var> by one and continue with the state machine. </p>
<dl class="switch">
<dt><dfn data-dfn-type="dfn" data-noexport="" id="scheme-start-state">scheme start state<a class="self-link" href="#scheme-start-state"></a></dfn>
<dd>
<ol>
<li>
<p>If <a data-link-type="dfn" href="#c">c</a> is an <a data-link-type="dfn" href="#ascii-alpha">ASCII alpha</a>,
append <a data-link-type="dfn" href="#c">c</a>, <a data-link-type="dfn" href="#ascii-lowercase">lowercased</a>, to <var>buffer</var>, and
set <var>state</var> to <a data-link-type="dfn" href="#scheme-state">scheme state</a>. </p>
<li>
<p>Otherwise, if <var>state override</var> is not given, set <var>state</var> to <a data-link-type="dfn" href="#no-scheme-state">no scheme state</a>, and decrease <var>pointer</var> by one. </p>
<li>
<p>Otherwise, <a data-link-type="dfn" href="#syntax-violation">syntax violation</a>, terminate this algorithm. </p>
</ol>
<dt><dfn data-dfn-type="dfn" data-noexport="" id="scheme-state">scheme state<a class="self-link" href="#scheme-state"></a></dfn>
<dd>
<ol>
<li>
<p>If <a data-link-type="dfn" href="#c">c</a> is an <a data-link-type="dfn" href="#ascii-alphanumeric">ASCII alphanumeric</a>, "<code>+</code>",
"<code>-</code>", or "<code>.</code>", append <a data-link-type="dfn" href="#c">c</a>, <a data-link-type="dfn" href="#ascii-lowercase">lowercased</a>, to <var>buffer</var>. </p>
<li>
<p>Otherwise, if <a data-link-type="dfn" href="#c">c</a> is "<code>:</code>", run these substeps: </p>
<ol>
<li>
<p>If <var>state override</var> is given, run these subsubsteps: </p>
<ol>
<li>
<p>If <var>url</var>’s <a data-link-type="dfn" href="#concept-url-scheme">scheme</a> is a <a data-link-type="dfn" href="#special-scheme">special scheme</a> and <var>buffer</var> is not, terminate this algorithm. </p>
<li>
<p>If <var>url</var>’s <a data-link-type="dfn" href="#concept-url-scheme">scheme</a> is not a <a data-link-type="dfn" href="#special-scheme">special scheme</a> and <var>buffer</var> is, terminate this algorithm. </p>