-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
1997 lines (1745 loc) · 71.2 KB
/
index.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" class="-debug">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="initial-scale=1, shrink-to-fit=no, user-scalable=no">
<title>URL Specification</title>
<link rel="stylesheet" href="style/base.css">
<link rel="stylesheet" href="style/style.css">
<script src="lib/specurl.min.js"></script>
<script src="scripts/main.js"></script>
</head>
<body>
<header>
<hgroup>
<h2 class=toc-exclude><!----></h2>
</hgroup>
</header>
<div id=tools>
<div id=menu>
<a id=icon href=#url-specification>🌲</a>
<ul>
<li><a href=#url-specification>Introduction</a></li>
<li><a href=#preliminaries>Preliminaries</a></li>
<li><a href=#url-model><span class=url>URL</span> Model</a></li>
<li><a href=#reference-resolution >Resolution</a></li>
<li><a href=#parsing>Parsing</a></li>
<li><a href=#host-parsing >Host Parsing</a></li>
<li><a href=#equivalences-and-normalisation >Normalisation</a></li>
<li><a href=#printing>Printing</a></li>
</ul>
</div>
<div id=tooltip></div>
</div>
<main>
<article>
<h1 id=url-specification>URL Specification</h1>
<!----------------------------->
<section class=-short>
<h2 class=toc-exclude style=display:none>URL Specification</h2>
<!----------------------------->
<p>
This document provides a concise formal definition of <span class=url>URL</span>s and
the language of <span class=url>URL</span>s. It offers a rephrasing of the
<a href="https://url.spec.whatwg.org/"><abbr class=-caps>WHATWG URL</abbr>
standard</a> in an effort to better reveal the internal structure of
<span class=url>URL</span>s and the operations on them.
It provides a formal grammar and a set of elementary operations that are eventually
combined together in such a way that the end result is equivalent with the
<abbr class=-caps>WHATWG</abbr> standard.
<p class=-inbetween>
The goals of this document are,
<ul class=-prose>
<li>
To provide a modular, concise formal specification of
<span class=url>URL</span>s that is behaviourally equivalent with, and
covers all of the <a href="https://url.spec.whatwg.org/"
><abbr class=-caps>WHATWG URL</abbr> standard</a> with the exception of
the web <abbr class=-caps>API</abbr>'s setters and the url-encoded
form format.
<li>
To provide a general model for <span class=url>URL</span>s that can
express relative references and to define reference resolution by means
of a number of elementary operations, in such a way that the end result is
in agreement with the <abbr class=-caps>WHATWG</abbr> standard.
<li>
To provide a concise way to describe the differences between the
<abbr class=-caps>WHATWG</abbr> standard and
<a href="https://tools.ietf.org/html/rfc3986"><abbr class=-caps>RFC</abbr> 3986</a>
and
<a href="https://tools.ietf.org/html/rfc3987"><abbr class=-caps>RFC</abbr> 3987</a>
as part of a larger effort;
<li>
To enable and support work towards an update of
<a href="https://tools.ietf.org/html/rfc3987"><abbr class=-caps>RFC</abbr> 3987</a>
that resolves the incompatibilities with the <abbr class=-caps>WHATWG</abbr> standard.
<li>
To enable and support editorial changes to the
<abbr class=-caps>WHATWG</abbr> standard in the hope to recover the
structural framework for relative references, normalisation and the hierarchy of
equivalence relations on <span class=url>URL</span>s that was put forward in
<a href="https://tools.ietf.org/html/rfc3986"><abbr class=-caps>RFC</abbr> 3986</a>.
<!-- <li>
To provide the authors of the <abbr class=-caps>WHATWG</abbr> standard
with a support document that is useful to them in their efforts to
understand and standardise the behaviour of web browsers. -->
</ul>
</section>
<!----------------------------->
<section class=-short>
<h2 class=toc-exclude>Status of this document</h2>
<!----------------------------->
<p class=note>
This is a development version of the specification.
<ul>
<li>
This is version 0.9.0 of the specification. This is a development
version.
<li>
The versioning scheme is specified by
<a href="https://semver.org/spec/v2.0.0.html">Semantic Versioning</a>.
<li>
This document is licensed under a
<a href="https://creativecommons.org/licenses/by-sa/2.0/">
Creative Commons - <abbr class=-caps>CC BY-SA</abbr> 2.0</a> license.
<li>
The development of this specification can be discussed on
<a href="https://github.com/alwinb/url-specification">GitHub</a>.
<li>
There is a <a href="https://github.com/alwinb/spec-url">reference implementation</a>
to accompany this specification.
<li>
The reference implementation currently passes 630 out of the 632
<span class=url>URL</span> constructor tests from the
<a href=https://web-platform-tests.org>web-platform-tests</a>.
</ul>
</section>
<!----------------------------->
<section class=-short>
<h2 class=toc-exclude>Structure of this document</h2>
<!----------------------------->
<p>
As of this writing, this document has a compact format that is focused specifically on
the definition and specification of <span class=url>URL</span>s and operations on
<span class=url>URL</span>s.
<p class=-inbetween>
The sections are laid out as follows.
<ul id=toc>
<!-- auto generated -->
</ul>
</section>
<!----------------------------->
<section><h2>Preliminaries</h2>
<!----------------------------->
<p>
This section introduces basic concepts and notational conventions which are used
throughout the rest of this document.
<h4>Sequences</h4>
<p>
This specification uses an algebraic notation for <i>sequence</i>s
that makes no distinction between one-element sequences and their first
element. It uses the following notation:
<div class="dfn-scope -inbetween">
<ul>
<li>
<dfn style=display:none>sequence</dfn>
The empty sequence is denoted by ε.
<li>
The concatenation of two sequences <var>S</var> and <var>T</var> is
denoted by <var>S</var>・<var>T</var>.
</ul>
<p style=margin-top:-.5rem>
Furthermore, the notation
<var>e</var> <b>:</b> <var>T</var> is used to denote the concatenation of a
single-element <var>e</var> in front of a sequence <var>T</var>.
</div>
<p>
The notation <var>e</var> <b>:</b> <var>T</var> may be used to inductively specify
operations on sequences. For example, the length of a sequence is defined by
<dfn class=noindex>length</dfn> ε = 0 and
<dfn class=noindex>length</dfn> (<var>e</var> <b>:</b> <var>T</var>) =
1 + <i>length</i> <var>T</var>.
<p style=margin-top:-.5rem>
Parentheses are used for disambiguation and as visual aides. Paired
parentheses are not part of a sequence-constructing operation.
<div class="dfn-scope +br">
<h4>Components</h4>
<p>
<dfn style=display:none>type</dfn>
The word <dfn>component</dfn> is used throughout this document to mean a
tagged value, denoted by (<var>type</var> <var>value</var>), where
<var>type</var> is taken from a predefined set of
<dfn>component-type</dfn>s.
The <i class=noindex>value</i> of a component may be a <i class=common>sequence</i>
of components itself, in which case the component may be referred to as a
<dfn>compound-component</dfn> for clarity.
<!--and the components present in its value may be referred to as
<dfn>sub-component</dfn>s.-->
<!-- add to dfn index -->
<!-- TODO I want to be able to add alt-name attributes to the dfn tags-->
<div style=display:none><dfn>value</dfn></div>
</div>
<p>
Both <i>component-type</i>s and their corresponding <i>component</i>-constructing operator are
typeset in boldface. For example, <b class=noindex>scheme</b> denotes a <i>component-type</i>,
whilst (<b class=noindex>scheme</b> <var>value</var>) denotes a
<b class=noindex>scheme</b>-<i>component</i>.
Again, parentheses are used to disambiguate and as visual aides. They are not part of
the <i class=common>component</i>-constructing operator.
<p>
When a collection of <i class=common>component</i>s contains exactly one
<i class=common>component</i> for a given <i class=common>component-type</i>,
then the <i class=common>type</i> may be used as a reference to the
<i class=common>component</i>'s
<i class=common>value</i>. For example, given a <i class=common>sequence</i> of
<i class=common>component</i>s
S := (<b class=noindex>dir</b> <var>x</var>・<b
class=noindex>file</b> <var>y</var>・<b
class=noindex>query</b>
<var>z</var>), the phrase
“the <b class=noindex>query</b> of S” identifies the
<i class=common>value</i> <var>z</var> whereas the phrase “the
<b class=noindex>query</b> <i class=common>component</i> of
S” identifies (<b class=noindex>query</b> <var>z</var>).
<h3>Strings and Grammars</h3>
<h4>Strings and Code-Points</h4>
<p class=-br>
For the purpose of this specification,
<ul class=dfn-scope>
<li>
A <dfn>string</dfn> is a <i class=common>sequence</i> of
<i>character</i>s.
<li>
A <dfn>character</dfn> is a single
<a href="https://www.unicode.org/versions/latest/">Unicode</a>
<i>code point</i>.
<li>
A <dfn>code point</dfn>, is a natural number
<var>n</var> < 17 × 2<sup>16</sup>.
<li>
The <dfn>empty string</dfn> is a <i class=common>sequence</i> of zero
code points. It is denoted by ε.
</ul>
<p>
Code points are denoted by a number in <em>hexadecimal</em> notation
preceded by <b class=noindex>u+</b>, in boldface. In addition, code points
that correspond to <i class=common>printable <abbr
class=-caps>ASCII</abbr> characters</i> are
often denoted by their corresponding glyph, typeset in monospace and on a
screened background.
For example, <b>u+41</b> and <code>A</code> denote the same
code point. Strings that contain only
<i class=common>printable <abbr class=-caps>ASCII</abbr> characters</i>
are often denoted as a connected sequence of glyphs, typeset likewise.
<p>
The <dfn class=common>printable <abbr
class=-caps>ASCII</abbr> characters</dfn> are
codepoints in the range <b>u+20</b> to <b>u+7E</b>, inclusive. Note that
this includes the space <i class=common>character</i> <b>u+20</b>.
<div class=dfn-scope>
<h4>Character Sets</h4>
<p>
A <dfn>character-set</dfn> is a set of <i>character</i>s.
A <dfn>character-range</dfn> is the largest <i class=common>character-set</i> that
includes a given least <i class=common>character</i> <var>c</var> and a greatest
<i class=common>character</i> <var>d</var>.
Such a <i>character-range</i> is denoted by
<span class=-nowrap>{ <var>c</var>–<var>d</var> }.</span>
The union of e.g. <span class=-nowrap>{ <var>a</var>–<var>b</var> }</span>
and <span class=-nowrap>{ <var>c</var>–<var>d</var> }</span>, is denoted by
<span class=-nowrap>{ <var>a</var>–<var>b</var>, <var>c</var>–<var>d</var> }</span>,
and this notation is generalised to <var>n</var>-ary unions.
Common <i class=common>character-set</i>s that are used throughout this document
are defined below:
</div>
<table class="grammar">
<tr>
<td><dfn>any</dfn>
<td> :=
<td class=-nowrap> { <b>u+0</b>–<b>u+10FFFF</b> }
<tr>
<td><dfn>control-c0</dfn>
<td> :=
<td class=-nowrap> { <b>u+0</b>–<b>u+1F</b> }
<tr>
<td><dfn>c0-space</dfn>
<td> :=
<td class=-nowrap> { <b>u+0</b>–<b>u+20</b> }
<tr>
<td><dfn>printable-<abbr class=-caps>ASCII</abbr></dfn>
<td> :=
<td> { <b>u+20</b>–<b>u+7E</b> } — i.e. { <code><span
style=width:1ch;display:inline-block;padding:0> </span></code>–<code>~</code> }
<tr>
<td><dfn>octal-digit</dfn>
<td> :=
<td class=-nowrap>{ <code>0</code>–<code>7</code> }
<tr>
<td><dfn>digit</dfn>
<td> :=
<td class=-nowrap> { <code>0</code>–<code>9</code> }
<tr>
<td><dfn>hex-digit</dfn>
<td> :=
<td><span class=-nowrap>{ <code>0</code>–<code>9</code>,
<code>A</code>–<code>F</code>, <code>a</code>–<code>f</code> }</span>
<tr>
<td><dfn>digit-nonzero</dfn>
<td> :=
<td> { <code>1</code>–<code>9</code> }
<tr>
<td><dfn>alpha</dfn>
<td> :=
<td class=-nowrap> { <code>A</code>–<code>Z</code>,
<code>a</code>–<code>z</code> }
<tr>
<td><dfn>del-c1</dfn>
<td> :=
<td> { <b>u+7F</b>–<b>u+9F</b> }
<tr>
<td><dfn>control-c1</dfn>
<td> :=
<td class=-nowrap> { <b>u+80</b>–<b>u+9F</b> }
<tr>
<td><dfn>latin-1</dfn>
<td> :=
<td class=-nowrap> { <b>u+A0</b>–<b>u+FF</b> }
<tr>
<td><dfn>surrogate</dfn>
<td> :=
<td class=-nowrap> { <b>u+D800</b>–<b>u+DFFF</b> }
<tr>
<td><dfn>non-char</dfn>
<td> :=
<td> { <b>u+FDD0</b>–<b>u+FDEF</b> }
∪ { <var>c</var> | <var>c</var> in <i>any</i> and
(<var>c</var> + 2) <b class=op>mod</b> 2<sup>16</sup> ≤ 1 }
<tr>
<td><dfn>base-char</dfn>
<td> :=
<td> <i>any</i> \ <i>control-c0</i> \ <i>del-c1</i> \ <i>surrogate</i> \ <i>non-char</i>
</table>
<h4>Grammars</h4>
<p>
The notation <var>name</var> ::= <var>expression</var> is used to define
a production rule of a grammar, where the <dfn>expression</dfn> uses
square brackets ( [ … ] ) <strong>for optional rules</strong>, a postfix
star ( * ) for zero-or-more, a postfix plus ( + ) for one-or-more, an infix
vertical line ( | ) for alternatives, monospaced type for literal
<i class=common>string</i>s
and an epsilon ( ε ) for the empty string. Parentheses are used for
grouping and disambiguation.
<h4>Pattern Testing</h4>
<p>
The shorthand notation <var>string</var> :: <var>rule</var> is used to
express that a <i class=common>string</i> <var>string</var> can be
generated by the production rule <var>rule</var> of a given grammar.
<br>Likewise, the notation
<var>string</var> :: <var>expression</var> is used to express that
<var>string</var> can be generated by <var>expression</var>.
<h3>Percent Coding</h3>
<p>
This subsection is analogous to the section
<a href="https://tools.ietf.org/html/rfc3986#section-2.1">Percent-Encoding</a> of
<abbr class=-caps>RFC</abbr> 3986 and the section
<a href="https://url.spec.whatwg.org/#percent-encoded-bytes">Percent-encoded bytes</a>
of the <abbr class=-caps>WHATWG</abbr> standard.
<!--On an abstract level, <em>percent encoding</em> is a means to include characters in
<i class=common>component</i> <i class=common>value</i>s that can not be used within
<i><span class=url>URL</span>-string</i>s directly.-->
<h4>Bytes</h4>
<p class=-br>
For the purpose of this specification,
<ul class=dfn-scope>
<li>
A <dfn>byte</dfn> is a natural number
<var>n</var> < 2<sup>8</sup>.
<li>
A <dfn>byte-sequence</dfn> is a <i>sequence</i> of
<i>byte</i>s.
</ul>
<div class=+br>
<h4>Percent Encoded Bytes</h4>
<p>
A non-empty <i>byte-sequence</i> may be <dfn>percent-encoded</dfn> as
a <i>string</i> by rendering each individual <i class=common>byte</i>
in two-digit hexadecimal notation, prefixed by <code>%</code>.
<table class="grammar dfn-scope">
<tr>
<td><dfn>pct-encoded-byte</dfn>
<td> ::=
<td class=-nowrap> <code>%</code> <i>hex-digit</i> <i>hex-digit</i>
<tr>
<td><dfn>pct-encoded-bytes</dfn>
<td> ::=
<td class=-nowrap><i>pct-encoded-byte</i>+
</table>
</div>
<h4>Percent Encoded String</h4>
<p>
A <dfn>percent-encoded–string</dfn> is a string that may have zero or more
<i>percent-encoded</i>–<i>byte-sequence</i>s
embedded within, as follows:
<table class="grammar">
<tr>
<td>pct-encoded-string
<td> ::=
<td>( <i>pct-encoded-bytes</i> | <i>uncoded</i> )*
<tr>
<td><dfn>uncoded</dfn>
<td> ::=
<td> <i>non-pct</i>+
<tr>
<td><dfn>non-pct</dfn>
<td> :=
<td> <i>any</i> \ { <code>%</code> }
</table>
<p>
The grammar above may be relaxed in situations where error recovery is desired.
This is achieved by adding a <i>pct-invalid</i> rule as follows:
</p>
<table class=grammar>
<tr>
<td>pct-encoded-string
<td> ::=
<td>( <i>pct-encoded-bytes</i> | <i>pct-invalid</i> | <i>uncoded</i> )*
<tr>
<td><dfn>pct-invalid</dfn>
<td> ::=
<td> <nowrap><code>%</code> [ <i>hex-digit</i> ]</nowrap>
</table>
<p>
There is an ambiguity in the loose grammar due to the overlap between <i>pct-encoded-byte</i>
and <i>pct-invalid</i> combined with <i>uncoded</i>. The ambiguity must be resolved by using the
<i>pct-encoded-byte</i> rule instead of the <i>pct-invalid</i> rule wherever possible.
<h4>Percent Encoding</h4>
<p>
To <i>percent-encode</i> a <i class=common>string</i> <var>string</var> using a given
<i class=common>character-set</i> <var>encode-set</var>
…
<!-- <h4>Percent Encode Set</h4>
<p>
A <dfn>percent-encode-set</dfn> is a subset of the
<i class=common>printable-<abbr class=-caps>ASCII</abbr></i> characters
that is used as a configuration argument to a
<i>percent-encode</i> operation on <i>string</i>s.
<p class=note>
This restricts the encode sets to printable ASCII.
Non-url codepoints must also be encoded, but it makes sense to mandate that
and not make it configurable via the encode set, but this is work in progress.
<br>-->
<p class=todo>
Wrap this up. Furthermore, this needs to discuss the encoding override, which is only
allowed for the query; all other components must use UTF8.
<h4>Percent Decoding</h4>
<p class=-br>
Percent decoding of strings is stratified into the following phases:
<ul>
<li>
Analyse the string as into <i>pct-encoded-bytes</i>, <i>pct-invalid</i> and <i>uncoded</i>
parts according to the <i>pct-encoded-string</i> grammar.
<li>
Convert the percent-coded-bytes to a <i>byte-sequence</i> and decode the byte sequence
to a <i>string</i> whilst leaving the <i>pct-invalid</i> and <i>uncoded</i> parts unmodified.
<li>
Recompose the string.
</ul>
<div class=todo>
Wrap this up.
Note that the decoding of the percent-coded-bytes must use UTF8.
</div>
</section>
<!------------------------>
<section><h2>URL Model</h2>
<!------------------------>
<p>
An <i><span class=url>URL</span></i> is a sequence of components that is
subject to a number of additional constraints. The ordering of the components
in the sequence is analogous to the hierarchical syntax of an
<abbr class=-caps>URI</abbr> as described
in <a href="https://tools.ietf.org/html/rfc3986#section-1.2.3">Hierarchical
Identifiers</a> in <abbr class=-caps>RFC</abbr> 3986.
<p>
It is important to stress the distinction between an
<i><span class=url>URL</span></i> and an
<i><span class=url>URL</span>-string</i>.
<br>
<span class=dfn-scope>
An <i class=url>URL</i> is a <em>structure</em>, indeed a special
sequence of components, whereas an <dfn><span class=url>URL</span>-string</dfn>
is a special kind of <i>string</i> that <em>represents</em> an
<i class=url>URL</i></span>. Conversions between <i class=url>URL</i>s
and <i class=common><span class=url>URL</span>-string</i>s are described in
the sections <a href="#parsing">Parsing</a>
and <a href="#printing">Printing</a>.
<div class="dfn-scope +br">
<h4>URL</h4>
<p>
An <dfn class=url>URL</dfn> is a <i>sequence</i> of
<i>component</i>s that occur in ascending order by <i>component-type</i>,
where <i class=noindex>component-type</i> is taken from
the ordered set:
<p class="-center">
<b>scheme</b> < <b>authority</b> < <b>drive</b>
< <b>path-root</b> < <b>dir</b> < <b>file</b>
< <b>query</b> < <b>fragment</b>.
<ul>
<li>
An <i class=url>URL</i> contains at most one
<i class=common>component</i> per <i class=common>type</i>,
except for <b>dir</b> <i class=common>component</i>s, of which it may have
any finite amount.
<li class=dfn-scope><dfn style=display:none>path-root-constraint</dfn>
If an <i class=url>URL</i> has an <b>authority</b> or a
<b>drive</b> <i class=common>component</i>, and it has a <b>dir</b> or a
<b>file</b> component, then it also has a <b>path-root</b>
<i class=common>component</i>.
</ul>
</div>
<div class="dfn-scope +br">
<h4>Authority</h4>
<p class=-br>
An <dfn>Authority</dfn><dfn style=display:none>authority</dfn>
is a sequence of components ordered by their type, taken from the ordered set:
<p class="-center">
<b>username</b> < <b>password</b> < <b>host</b> < <b>port</b>.
</div>
<ul>
<li>
Authorities have at most one <i class=common>component</i> per
<i class=common>type</i>.
<li>
If an Authority has a <b>password</b> <i class=common>component</i> then it
also has a <b>username</b> <i class=common>component</i>.
<li>
If an Authority has a <b>username</b> or a <b>port</b>
<i class=common>component</i> then it also has a <b>host</b>
<i class=common>component</i>.
</ul>
<div class="dfn-scope +br">
<h4>Host</h4>
<p>
A <dfn>Host</dfn> is either:
<div><ul class=-inline>
<li>
An ipv6-address,
<li>
an opaque-host,
<li>
an ipv4-address, or
<li>
a domain-name.
</ul></div>
</div>
<h4>URL components</h4>
<p>
Whenever present, the <i class=common>component</i>s of an <span class=url>URL</span>
are subject to the following constraints:
<ul>
<li class=dfn-scope>
<dfn style=display:none><b>scheme</b>-string</dfn>
The <dfn><b>scheme</b></dfn> of an <i class=url>URL</i>
is a <i class=common>string</i>
<span class=rule><var>scheme</var> :: <i>alpha</i> (<i>alpha</i>
| <i>digit</i> | <code>+</code> | <code>-</code>
| <code>.</code>)*</span>.
<li class=dfn-scope>
The <dfn><b>authority</b></dfn> of an <i class=url>URL</i>
is
an <i>Authority</i>.
<li class=dfn-scope>
The <dfn><b>path-root</b></dfn> of an <i class=url>URL</i>
is the <i class=common>string</i> <code>/</code>.
<li class=dfn-scope>
The <dfn><b>drive</b></dfn> of an <i class=url>URL</i>
is a
<i class=common>string</i> <span class=-nowrap><var>drive</var> ::
<i>alpha</i> (<code>:</code> | <code>|</code>)</span>.
<li class=dfn-scope>
The <dfn><b>file</b></dfn> of an <i class=url>URL</i>
is a nonempty <i class=common>string</i>.
<!-- <li>
For all other components present, the components’ values are
<i class=common>string</i>s. -->
<li class=dfn-scope>
The <dfn><b>host</b></dfn> of an <i>Authority</i> is a <i>Host</i>.
<li class=dfn-scope>
The <dfn><b>port</b></dfn> of an <i>Authority</i> is either ε
or a natural number <var>n</var> < 2<sup>16</sup>.
<li class=dfn-scope>
For all other <i class=common>component</i>s present, the
<i class=common>component</i>s' <i class=common>value</i>s
are <i class=common>string</i>s.
</ul>
<ul style=display:none>
<li class=dfn-scope>
A <dfn><b>dir</b></dfn> component is a component (<b>dir</b> <var>name</var>)
where <var>name</var> is a string.
<li class=dfn-scope>
The <dfn><b>query</b></dfn> of an <i class=url>URL</i>,
is a string.
<li class=dfn-scope>
The <dfn><b>fragment</b></dfn> of an <i class=url>URL</i>,
is a string.
</ul>
<p>
Note that arbitrary <i class=common>code point</i>s are allowed in
<i class=common>component</i> <i class=common>value</i>s
unless explicitly specified otherwise. The restrictions on the code points
in an <i><span class=url>URL</span>-string</i> is discussed in
the <a href=#parsing>Parsing</a> section.
<h3>Types and Shapes</h3>
<p>
There is an additional number of soft constraints that must be met for
an <i class=url>URL</i> in order to be called <i>valid</i>.
However, implementations must tolerate <i><span class=url>URL</span></i>s
that are not <i>valid</i> as an error recovery strategy.
<div class="dfn-scope +br">
<h4>Valid URL</h4>
<p>
A <dfn>valid</dfn> <i class=url>URL</i> must not have a <b>username</b> or a
<b>password</b> component and it must not have <i class=common>component</i>s
that contain invalid percent-encode sequences.
</div>
<p>
There is a further categorisation of <i class=url>URL</i>s that is used in
several of the operations that will be defined later.
<div class="dfn-scope +br">
<h4>Web-URL</h4>
<p class=-br>
A <dfn>web-<span class=url>URL</span></dfn> is an
<i class=url>URL</i> that has a <i>web-<b>scheme</b></i>.
<!-- A <dfn>non-special <span class=url>URL</span></dfn> is an
<span class=url>URL</span> that is not <i>special</i>. -->
A <dfn>web-<b>scheme</b></dfn> is a <i class=common>string</i>
<var>scheme</var> such that
(lowercase <var>scheme</var>) :: <span class=rule>
<code>http</code> | <code>https</code> | <code>ws</code> |
<code>wss</code> | <code>ftp</code></span>.
</div>
<div class="dfn-scope +br">
<h4>File-URL</h4>
<p>
A <dfn>file-<span class=url>URL</span></dfn> is an
<i class=url>URL</i> that has a <i>file-<b>scheme</b></i>.
A <dfn>file-<b>scheme</b></dfn> is a <i class=common>string</i>
<var>scheme</var> such that
<span class=rule>(lowercase <var>scheme</var>) :: <code>file</code></span>.
</div>
</section>
<!----------------------------------->
<section><h2>Reference Resolution</h2>
<!----------------------------------->
<p>
This section defines reference resolution operations that are analogous to the
algorithms that are described in the chapter
<a href="https://tools.ietf.org/html/rfc3986#section-5">Reference Resolution</a> of
<abbr class=-caps>RFC</abbr> 3986. The operations that are defined in this section are
used in a subsequent section to define a <em>parse-resolve-and-normalise</em>
operation that accurately describes the behaviour of the
‘<a href="https://url.spec.whatwg.org/#concept-basic-url-parser">basic
<span class=url>URL</span> parser</a>’ as defined in the
<abbr class=-caps>WHATWG URL</abbr> standard.
<p>
Reference resolution as defined in this section does not involve
<i><span class=url>URL</span>-string</i>s. It operates on <i class=url>URL</i>s as
defined in the <a href=#url-model><span class=url>URL</span> Model</a> section above.
In contrast with <abbr class=-caps>RFC</abbr> 3986 and with the
<abbr class=-caps>WHATWG</abbr> standard, it does <strong>not</strong> do additional
normalisation, which is relegated to the section
<a href=#equivalences-and-normalisation>Equivalences and Normalisation</a> instead.
<h3>Order and Prefix operations</h3>
<p>
A property that is particularly useful is the <i>order</i> of an <i class=url>URL</i>.
Colloquially, the <i class=common>order</i> is the
<i class=common>type</i> of the first <i class=common>component</i>
of an <i class=url>URL</i>. The <i class=common>order</i>
may be used as an argument to specify various prefixes of an
<i class=url>URL</i>.
<div class="dfn-scope +br">
<h4>The Order of an <span class=url>URL</span></h4>
<p class=-br>
The <dfn>order</dfn> of an <i class=url>URL</i> (<dfn class=fn>ord</dfn>
<var>url</var>) is
defined to be:
<ul>
<li>
<b>fragment</b> if <var>url</var> is the empty <i class=url>URL</i>.
<li>
The <i class=common>type</i> of its first <i class=common>component</i>
otherwise.
</ul>
<h4>Order-Limited Prefix</h4>
<p class=-br>
The <dfn>order-limited prefix</dfn>
(<var>url</var> <dfn class=op>upto</dfn> <var>order</var>)
is defined to be <br>
the <em>shortest</em> prefix of <var>url</var> that contains:
<ul>
<li>
all <i class=common>component</i>s of <em>url</em> with a
<i class=common>type</i> strictly
smaller than <var>order</var> and
<li>
all <b>dir</b> <i class=common>component</i>s with a
<i class=common>type</i> weakly smaller
than <var>order</var>.
</ul>
</div>
<h3>The Goto Operation</h3>
<p>
Based on the <i class=common>order</i> and the <i class=common>order-limited
prefix</i> one can define a “<i class=common>goto</i>” operation that is
analogous to the “merge” operation that is defined in the subsection
<a href="https://tools.ietf.org/html/rfc3986#section-5.2.2">Transform References</a>
of <abbr class=-caps>RFC</abbr> 3986.
I have chosen the name “goto” to avert incorrect assumptions about
commutativity. The operation is not commutative, but it is associative.
<div class="dfn-scope">
<h4>Goto</h4>
<p>
The <dfn>goto</dfn> operation
<span class=-nowrap>(<var>url<sub>1</sub></var> <dfn class=op>goto</dfn>
<var>url<sub>2</sub></var>)</span> is defined to return
<br>
the <em>shortest</em> <i class=url>URL</i> that has
<var>url<sub>1</sub></var> <b class=fn>upto</b>
(<b class=fn>ord</b> <var>url<sub>2</sub></var>) as a
prefix and <var>url<sub>2</sub></var> as a postfix.
</div>
<h4>Goto Properties</h4>
<p class=-br>
The <i>goto</i> operation has a number of pleasing mathematical
properties, as follows:
<ul>
<li>
<i class=op>ord</i> (<var>url<sub>1</sub></var> <i class=op>goto</i>
<var>url<sub>2</sub></var>) is the least type of
{<i class=op>ord</i> <var>url<sub>1</sub></var>,
<i class=op>ord</i> <var>url<sub>2</sub></var>}.
<li>
(<var>url<sub>1</sub></var> <i class=op>goto</i>
<var>url<sub>2</sub></var>) <i class=op>goto</i>
<var>url<sub>3</sub></var> = <var>url<sub>1</sub></var>
<i class=op>goto</i> (<var>url<sub>2</sub></var> <i class=op>goto</i>
<var>url<sub>3</sub></var>).
<li>
ε <i class=op>goto</i> <var>url<sub>2</sub></var> =
<var>url<sub>2</sub></var>.
<li>
<var>url<sub>1</sub></var> <i class=op>goto</i> ε =
<var>url<sub>1</sub></var> — if <var>url<sub>1</sub></var> does not
have a <b>fragment</b>.
<li>
<var>url<sub>2</sub></var> is a postfix of (<var>url<sub>1</sub></var>
<i class=op>goto</i> <var>url<sub>2</sub></var>).
</ul>
<p>
Be aware that the <i>goto</i> operation does a bit more than
sequence concatenation. In some cases it creates a <b>path-root</b>
component to satisfy the <i>path-root-constraint</i>
of the <i class=url>URL</i> model.
For example, if <var>url<sub>1</sub></var> is the
<i class=url>URL</i> represented by <code>//host</code> and <var>url<sub>2</sub></var>
is the <i class=url>URL</i> represented by <code>foo/bar</code>
then (<var>url<sub>1</sub></var> <i class=op>goto</i> <var>url<sub>2</sub></var>)
is represented by <code>//host/foo/bar</code>, thus containing a <b>path-root</b> even
though neither <var>url<sub>1</sub></var> nor <var>url<sub>2</sub></var> has one.
</p>
<h3>Forcing</h3>
<p>
There is an additional operation on <i class=url>URL</i>s that I have named <i>force</i>.
The <i class=common>force</i> operation is used as a final step in the process of resolving a
<i>web-<span class=url>URL</span></i> or a <i>file-<span class=url>URL</span></i>.
The operation ensures that the resulting <span class=url>URL</span> has an <b>authority</b>
token and a <b>path-root</b> token. Note that it is possible for the force operations to
<strong>fail</strong>.
</p>
<div class="dfn-scope +br">
<h4>Forced File URL</h4>
<p class=-br>
To <dfn>force</dfn> a <i>file-<span class=url>URL</span></i> <var>url</var>:
<ul>
<li>
If <var>url</var> does <strong>not</strong> have an <b>authority</b> then set its
<b>authority</b> component to (<b>authority</b> ε).
<li>
If otherwise the <b>authority</b> of <var>url</var> has a
<b>username</b> or a <b>port</b> then <strong>fail</strong>.
<li>
If <var>url</var> does not have a <b>drive</b> then set its
<b>path-root</b> component to (<b>path-root</b> <code>/</code>).
</ul>
</div>
<div class="dfn-scope +br">
<h4>Forced Web URL</h4>
<p class=-br>
To <dfn>force</dfn> a <i>web-<span class=url>URL</span></i>
<var>url</var>:
<ul>
<li>
Set the <b>path-root</b> component of <var>url</var> to
(<b>path-root</b> <code>/</code>).
<li>
If <var>url</var> has a non-empty <b>authority</b> then return.
<li>
Otherwise let <var>component</var> be the first <b>dir</b> or
<b>file</b> <i class=common>component</i> whose value is not ε.
<br>If no such <i class=common>component</i> exists, <strong>fail</strong>.
<li>
Remove all <b>dir</b> or <b>file</b> <i class=common>component</i>s that
precede <var>component</var> and remove <var>component</var> as well.
<li>
Let <var>auth</var> be the <i>value</i> of <var>component</var> parsed as
an <i>Authority</i> and set the <b>authority</b> of <var>url</var> to
<var>auth</var>. If the value cannot be parsed as an <i>Authority</i>
then <strong>fail</strong>.
</ul>
</div>
<h4>Force Properties</h4>
<p>
The <i>force</i> operation lacks a number of nice properties with respect to the
<i>goto</i> operation. The following equalities do not hold in general:
<table class=grammar>
<tr>
<td><i class=op>force</i> ((<i class=op>force</i> <var>url<sub>1</sub></var>)
<i class=op>goto</i>
(<i class=op>force</i> <var>url<sub>2</sub></var>))
<td> ≠
<td><i class=op>force</i> (<var>url<sub>1</sub></var>
<i class=op>goto</i>
<var>url<sub>2</sub></var>)
<tr>
<td><i class=op>force</i> ((<i class=op>force</i> <var>url<sub>1</sub></var>)
<i class=op>goto</i>
<var>url<sub>2</sub></var>)
<td> ≠
<td><i class=op>force</i> (<var>url<sub>1</sub></var>
<i class=op>goto</i>
<var>url<sub>2</sub></var>)
<tr>
<td><i class=op>force</i> (<var>url<sub>1</sub></var>
<i class=op>goto</i>
(<i class=op>force</i> <var>url<sub>2</sub></var>))
<td> ≠
<td><i class=op>force</i> (<var>url<sub>1</sub></var>
<i class=op>goto</i>
<var>url<sub>2</sub></var>)
</table>
<h3>Resolution</h3>
<p>
The subsection
<a href="https://datatracker.ietf.org/doc/html/rfc3986#section-5.2.2"
>Transform References</a> of <abbr class=-caps>RFC</abbr> 3986 specifies <em>two</em>
variants of reference resolution. A generic, <em>strict</em> variant and an
alternative <em>non-strict</em> variant.
This specification adds a third variant that is used to specify the behaviour of
web-browsers.
I have chosen to name the strict variant <i>generic resolution</i> and the
<em>non-strict</em> variant <i>legacy resolution</i>, so that the words
the words <em>strict</em> and <em>non-strict</em> can be used as modifiers
later on.
<!--<p>
As an example, consider resolving the <abbr class=-url>URL</abbr> represented by
<code>scheme:foo/bar</code> against the <abbr class=-url>URL</abbr> represented by
<code>scheme://host/</code>. If <i>legacy resolution</i> is used, then the
<b>scheme</b> of the reference is ignored and the resolution results in
<code>scheme://host/foo/bar</code>. However, <i>generic resolution</i> results in
<code>scheme:foo/bar</code> — notice that the result does nnot have an authority. -->
<div class="dfn-scope +br" id="resolution">
<div style=display:none>
<dfn>resolution</dfn>
<dfn>resolve</dfn>
<dfn>generic resolution</dfn>
<dfn>legacy resolution</dfn>
</div>
<h4>Generic Resolution</h4>
<p>
The <dfn>generic resolution</dfn>
<span class=-nowrap>(<dfn class=op>generic-resolve</dfn> <var>url<sub>1</sub></var>
<var>url<sub>2</sub></var>)</span> of
an <span class=url>URL</span> <var>url<sub>1</sub></var> against
an <span class=url>URL</span> <var>url<sub>2</sub></var> is defined to be
<var>url<sub>2</sub></var> <i class=op>goto</i> <var>url<sub>1</sub></var>
— if <var>url<sub>2</sub></var> has a <b>scheme</b> or <var>url<sub>1</sub></var>
has a <b>scheme</b>. Otherwise resolution <strong>fails</strong>.
<h4>Legacy Resolution</h4>
<p class=-br>
The <dfn>legacy resolution</dfn>
<span class=-nowrap>(<dfn class=op>legacy-resolve</dfn> <var>url<sub>1</sub></var>
<var>url<sub>2</sub></var>)</span> is defined to be the
<i class=common>generic resolution</i>
(<b class=op>generic-resolve</b> <var>~url<sub>1</sub></var> <var>url<sub>2</sub></var>)
where <var>~url<sub>1</sub></var> is:
<ul>
<li>
<var>url<sub>1</sub></var> with its <b>scheme</b> removed if both
<var>url<sub>1</sub></var> and <var>url<sub>2</sub></var> have a <b>scheme</b>,
and the <i class=common>value</i> of their <b>scheme</b>
<i class=common>component</i>s case-insensitively compare equal, or
<li>
<em>url<sub>1</sub></em> itself otherwise.
</ul>
</div> <!-- Resolution -->
<p>
Based on the <i>generic resolution</i>, and the
<i>legacy resolution</i> and the <i>force</i> operations as defined above, it is now
possible to define a reference resolution operation that can be used to characterise
the behaviour that is specified in the <abbr class=-caps>WHATWG</abbr> standard.
<div class="dfn-scope +br" id="whatwg-resolution">
<div style=display:none>
<dfn>WHATWG-resolve</dfn>
<dfn>WHATWG-resolution</dfn>
</div>