-
Notifications
You must be signed in to change notification settings - Fork 9
/
url.bs
3211 lines (2524 loc) · 109 KB
/
url.bs
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
<pre class="metadata">
Title: URL Standard
Group: WebSpecs
H1: URL
Shortname: url
Status: LS
No Editor: true
Abstract: The URL Standard defines URLs, domains, IP addresses, the <code title>application/x-www-form-urlencoded</code> format, and their APIs.
Indent: 2
</pre>
<style>
.grammar-rule a, .grammar-rule span {
color: black;
background-color: hsl(120, 100%, 90%);
font-weight: bold;
padding: 2px;
border: 2px solid black;
}
.big-issue, .XXX { color: #E50000; background: white; border: solid red; padding: 0.5em; margin: 1em 0; }
.big-issue, .XXX { border-radius: 0.5em }
.big-issue > :first-child, .XXX > :first-child { margin-top: 0; }
p .big-issue, p .XXX { line-height: 3em; }
table { border-collapse: collapse; border-style: hidden hidden none hidden; }
table thead, table tbody { border-bottom: solid; }
table tbody th { text-align: left; }
table tbody th:first-child { border-left: solid; }
table td, table th { border-left: solid; border-right: solid; border-bottom:
solid thin; vertical-align: top; padding: 0.2em; }
.dfnPanel {
display: inline;
position: absolute;
z-index: 35;
height: auto;
width: auto;
padding: 0.5em 0.75em;
font: small Helvetica Neue, sans-serif, Droid Sans Fallback;
background: #DDDDDD;
color: black;
border: outset 0.2em;
}
.dfnPanel * { margin: 0; padding: 0; font: inherit; text-indent: 0; }
.dfnPanel :link, .dfnPanel :visited { color: black; }
.dfnPanel p:not(.spec-link) { font-weight: bolder; }
.dfnPanel * + p { margin-top: 0.25em; }
.dfnPanel li { list-style-position: inside; }
</style>
<h2 id=goals class=no-num>Goals</h2>
<p>The URL standard takes the following approach towards making URLs fully interoperable:
<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.
[[RFC3986]]
[[RFC3987]]
<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>.
<li><p>Supplanting <a href="https://tools.ietf.org/html/rfc6454#section-4">Origin of a URI [sic]</a>.
[[RFC6454]]
<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 interface>URL</a></code>
object as well for URL manipulation without usage of HTML elements. (Useful
for JavaScript worker environments.)
</ul>
<p class=note>As the editors learn more about the subject matter the goals
might increase in scope somewhat.
<h2 id=urls>URLs</h2>
<!-- History behind URL as term:
http://lists.w3.org/Archives/Public/uri/2012Oct/0080.html -->
<p>A <dfn id=concept-url title='URL'>URL</dfn> is a universal identifier.
<p>A <a>URL</a> consists of components, namely a
<a title='URL scheme'>scheme</a>,
<a title='URL scheme data'>scheme data</a>,
<a title='URL username'>username</a>,
<a title='URL password'>password</a>,
<a title='URL host'>host</a>,
<a title='URL port'>port</a>,
<a title='URL path'>path</a>,
<a title='URL query'>query</a>, and
<a title='URL fragment'>fragment</a>.
<p class="example">
<code>http://username:[email protected]:8000/path?query#fragment</code>
contains values for all <a>URL</a> components except
<a title="URL scheme data">scheme data</a>.
</p>
<p class="example">
<code>javascript:doSomething()</code> contains values for only
<a title='URL scheme'>scheme</a> and
<a title='URL scheme data'>scheme data</a>.
</p>
<p>A <a>URL</a>'s <dfn id=concept-url-scheme title='URL scheme'>scheme</dfn> is
a string that identifies the type of <a>URL</a> and can be used to
dispatch a <a>URL</a> for further processing after
<a title='URL parser'>parsing</a>. It is initially null.
<p>A <a>URL</a>'s
<dfn id=concept-url-scheme-data title='URL scheme data'>scheme data</dfn> is a string holding the contents of a
<a>URL</a>. It is initially null.
<p class="note no-backref">A <a>URL</a>'s
<a title='URL scheme data'>scheme data</a> will be null if its initial
<a title='URL scheme'>scheme</a> is a <a>relative scheme</a>, and
otherwise will be the only component other than <a title='URL
scheme'>scheme</a> that differs from its initial value.
<p>A <a>URL</a>'s <dfn id=concept-url-username title='URL username'>username</dfn>
is a string identifying a user. It is initially the empty string.
<p>A <a>URL</a>'s <dfn id=concept-url-password title='URL password'>password</dfn>
is either null or a string identifying a user's credentials. It is initially null.
<p>A <a>URL</a>'s <dfn id=concept-url-host title='URL host'>host</dfn> is
either null or a <a>host</a>. It is initially null.
<p>A <a>URL</a>'s <dfn id=concept-url-port title='URL port'>port</dfn> is a
string that identifies a networking port. It is initially the empty string.
<p>A <a>URL</a>'s <dfn id=concept-url-path title='URL path'>path</dfn> is a
list of zero or more strings holding data, usually identifying a location in hierarchical
form. It is initially the empty list.
<p>A <a>URL</a>'s <dfn id=concept-url-query title='URL query'>query</dfn> is
either null or a string holding data. It is initially null.
<p>A <a>URL</a>'s <dfn id=concept-url-fragment title='URL fragment'>fragment</dfn>
is either null or a string holding data that can be used for further processing on the
resource the <a>URL</a>'s other components identify.
It is initially null.
<p>A <a>URL</a> also has an associated
<dfn id=concept-url-object title='URL object'>object</dfn> that is either null or a
<code><a>Blob</a></code>. It is initially null.
[[!FILEAPI]]
<p class="note">At this point this is used primarily to support "<code>blob</code>"
URLs, but others can be added going forward, hence "object".
<p>A <dfn>relative scheme</dfn> is a
<a title='URL scheme'>scheme</a> listed in the first column of
the following table. A <dfn>default port</dfn> is a
<a>relative scheme</a>'s optional corresponding
<a title='URL port'>port</a> and is listed in the second column
on the same row.
<table>
<tr><th><a title='URL scheme'>scheme</a>
<th><a title='URL port'>port</a>
<tr><td>"<code>ftp</code>"<td>"<code>21</code>"
<tr><td>"<code>file</code>"<td>
<tr><td>"<code>gopher</code>"<td>"<code>70</code>"
<tr><td>"<code>http</code>"<td>"<code>80</code>"
<tr><td>"<code>https</code>"<td>"<code>443</code>"
<tr><td>"<code>ws</code>"<td>"<code>80</code>"
<tr><td>"<code>wss</code>"<td>"<code>443</code>"
</table>
<!-- The best reason I have for listing "gopher" is Google does it too:
https://code.google.com/p/google-url/source/browse/trunk/src/url_canon_stdurl.cc#120
It seems fine to remain compatible on that front, no need to support it
elsewhere though. -->
<p>A <a>URL</a>
<dfn title="include credentials">includes credentials</dfn> if either its
<a title='URL username'>username</a> is not the empty string or its
<a title='URL password'>password</a> is non-null.
<!-- used by Fetch -->
<p>A <a>URL</a> can be designated as
<dfn id=concept-base-url title='base URL'>base URL</dfn>.
<p class="note no-backref">A <a>base URL</a> is useful for
the <a>URL parser</a> when the input is potentially a
<a>relative URL</a>.
<h3 id=url-writing>Authoring Requirements</h3>
Two types of parse errors are defined. <dfn title='parse exception'>Parse
exceptions</dfn> terminate parsing and must be implemented by all conforming
implementations. By contrast, user agents are encouraged, but not required,
to expose <dfn title='conformance error'>conformance errors</dfn> somehow.
If parsing a given input results in the detection of multiple
<a>conformance errors</a>, user agents may chose to only report a subset of
the errors detected.
<!-- http://tantek.com/2011/238/b1/many-ways-slice-url-name-pieces -->
<p>A <a>URL</a> must be written as either a
<a>relative URL</a> or an
<a>absolute URL</a>, optionally followed by
"<code>#</code>" and a
<a title='URL fragment'>fragment</a>.
<p>An <dfn id=concept-absolute-url title='absolute URL'>absolute URL</dfn> must be a
<a title='URL scheme'>scheme</a>, followed by
"<code>:</code>", followed by either a
<a>scheme-relative URL</a>, if
<a title='URL scheme'>scheme</a> is a <a>relative scheme</a>, or
<a title='URL scheme data'>scheme data</a> otherwise, optionally followed
by "<code>?</code>" and a <a title='URL query'>query</a>.
<p>A <a title='URL scheme'>scheme</a> must be one
<a>ASCII alpha</a>, followed by zero or more of
<a>ASCII alphanumeric</a>, "<code>+</code>",
"<code>-</code>", and "<code>.</code>". A
<a title='URL scheme'>scheme</a> must be registered
<span class=XXX>...</span>.
<p>The syntax of <a title='URL scheme data'>scheme data</a>
depends on the <a title='URL scheme'>scheme</a> and is typically
defined alongside it. Standards must define
<a title='URL scheme data'>scheme data</a> within the constraints of zero or
more <a>URL units</a>, excluding "<code>?</code>".
<p>A <dfn id=concept-relative-url title='relative URL'>relative URL</dfn> must be either a
<a>scheme-relative URL</a>, an
<a>absolute-path-relative URL</a>,
or a <a>path-relative URL</a> that
does not start with a <a title='URL scheme'>scheme</a> and
"<code>:</code>", optionally followed by a "<code>?</code>" and
a <a title='URL query'>query</a>.
<p>At the point where a <a>relative URL</a> is
<a title='URL parser'>parsed</a>, a
<a>base URL</a> must be in scope.
<p>A <dfn id=concept-scheme-relative-url title='scheme-relative URL'>scheme-relative URL</dfn> must be
"<code>//</code>", optionally followed by
<a title='URL Userinfo'>userinfo</a> and "<code>@</code>",
followed by a <a>host</a>, optionally followed
by "<code>:</code>" and a <a title='URL port'>port</a>,
optionally followed by an
<a>absolute-path-relative URL</a>.
<p><dfn id=concept-url-userinfo title='URL Userinfo'>Userinfo</dfn> must be a
<a title='URL username'>username</a>, optionally followed by a
"<code>:</code>" and a
<a title='URL password'>password</a>.
<p>A <a title='URL username'>username</a> must be zero or more
<a>URL units</a>, excluding "<code>/</code>",
"<code>:</code>, "<code>?</code>", and "<code>@</code>".
<!-- password without ":" (sorted on ASCII position) -->
<p>A <a title='URL password'>password</a> must be zero or more
<a>URL units</a>, excluding "<code>/</code>",
"<code>?</code>", and "<code>@</code>".
<p>A <a>host</a> must be either a <a>domain</a>,
or an <a title='IPv4'>IPv4 address</a>,
or "<code>[</code>" followed
by an <a title='IPv6'>IPv6 address</a> followed by
"<code>]</code>".
<p>A <a>domain</a> must be a string that is a
<a>valid domain</a>.
<p class=XXX>Textual representation of <a title='IPv4'>IPv4 address</a> does
not appear to be defined by an RFC. See
<a href="https://tools.ietf.org/html/draft-main-ipaddr-text-rep-00">Textual
Representation of IPv4 and IPv6 Addresses</a> for some history.
<p>An <a title='IPv6'>IPv6 address</a> is defined in the
<a href="http://tools.ietf.org/html/rfc4291#section-2.2">"Text Representation of Addresses" chapter of IP Version 6 Addressing Architecture</a>.
[[!RFC4291]]
<!-- http://tools.ietf.org/html/rfc5952 updates that RFC, but it seems as
far as what developers can do we should be liberal
XXX should we define the format inline instead just like STD 66? -->
<p>A <a title='URL port'>port</a> must be zero or more
<a>ASCII digits</a>.
<p>An
<dfn id=concept-absolute-path-relative-url title='absolute-path-relative URL'>absolute-path-relative URL</dfn>
must be "<code>/</code>", followed by a
<a>path-relative URL</a> that does not
start with "<code>/</code>".
<p>A <dfn id=concept-path-relative-url title='path-relative URL'>path-relative URL</dfn> must be zero or
more <a title="path segment">path segments</a> separated from each
other by a "<code>/</code>". The first segment (if any) of a <a>path-relative
URL</a> must not contain a colon (<code>U+003A</code>).
<p>A <dfn>path segment</dfn> must be zero or more <a>URL units</a>,
excluding "<code>/</code>" and "<code>?</code>".
<p>A <a title='URL query'>query</a> must be zero or more
<a>URL units</a>.
<p>A <a title='URL fragment'>fragment</a> must be zero or more
<a>URL units</a>.
<p>The <dfn>URL code points</dfn> are <a>ASCII alphanumeric</a>,
"<code>!</code>",<!-- 0x21, sub-delims -->
"<code>$</code>",<!-- 0x24, sub-delims -->
"<code>&</code>",<!-- 0x26, sub-delims -->
"<code>'</code>",<!-- 0x27, sub-delims -->
"<code>(</code>",<!-- 0x28, sub-delims -->
"<code>)</code>",<!-- 0x29, sub-delims -->
"<code>*</code>",<!-- 0x2A, sub-delims -->
"<code>+</code>",<!-- 0x2B, sub-delims -->
"<code>,</code>",<!-- 0x2C, sub-delims -->
"<code>-</code>",<!-- 0x2D, iunreserved -->
"<code>.</code>",<!-- 0x2E, iunreserved -->
"<code>/</code>",<!-- 0x2F, iquery/ifragment -->
"<code>:</code>",<!-- 0x3A, ipchar -->
"<code>;</code>",<!-- 0x3B, sub-delims -->
"<code>=</code>",<!-- 0x3D, sub-delims -->
"<code>?</code>",<!-- 0x3F, iquery/ifragment -->
"<code>@</code>",<!-- 0x40, ipchar -->
"<code>_</code>",<!-- 0x5F, iunreserved -->
"<code>~</code>",<!-- 0x7E, iunreserved -->
and code points in the ranges
U+00A0 to U+D7FF,
U+E000 to <!--U+F8FF,
U+F900 to -->U+FDCF,
U+FDF0 to U+FFFD,<!-- changed relative to IRI from U+FFEF to U+FFFD to align with HTML-->
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,<!-- changed relative to IRI from E1000 to E0000 to align with HTML-->
U+F0000 to U+FFFFD,
U+100000 to U+10FFFD.
<p class=note>Code points higher than U+009F will be converted to
<a title="percent-encoded byte">percent-encoded bytes</a> by the
<a>URL parser</a>, except for code points appearing in
<a title="URL fragment">fragments</a>.
<p>The <dfn>URL units</dfn> are <a>URL code points</a> and
<a title="percent-encoded byte">percent-encoded bytes</a>.
<h3 id=url-parsing>Parsers</h3>
<p>The <dfn id=concept-url-parser title='URL parser'>URL parser</dfn> takes a string
<var>input</var>, optionally with a
<a>base URL</a> <var>base</var>, and
optionally with an <a>encoding</a>
<var>encoding override</var>, and then runs these steps:
<ol>
<li><p>Let <var>url</var> be the result of running the
<a>basic URL parser</a> on <var>input</var>
with <var>base</var>, and <var>encoding override</var> as provided.
<li><p>If <var>url</var> is failure, return failure.
<li><p>If <var>url</var>'s <a title='URL scheme'>scheme</a> is not
"<code>blob</code>", return <var>url</var>.
<li><p>If <var>url</var>'s <a title='URL scheme data'>scheme data</a>
is not in the <a>blob URL store</a>, return
<var>url</var>. [[!FILEAPI]]
<li><p>Set <var>url</var>'s <a title='URL object'>object</a> to a
<a>structured clone</a> of the entry in the
<a>blob URL store</a> corresponding to
<var>url</var>'s <a title='URL scheme data'>scheme data</a>.
[[!HTML]]
<li><p>Return <var>url</var>.
</ol>
<hr>
<p>The <dfn id=concept-basic-url-parser title='basic URL parser'>basic URL parser</dfn> takes a string
<var>input</var>, optionally with a
<a>base URL</a> <var>base</var>,
optionally with an <a>encoding</a>
<var>encoding override</var>, optionally with an
<a>URL</a> <var>url</var> and a state override
<var>state override</var>, and then runs these steps:
<div class="note no-backref">
<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 methods of objects implementing the <code><a interface>URLUtils</a></code> interface.
[[!HTML]]
<p>When the <var>url</var> and <var>state override</var> arguments are not
passed the <a>basic URL parser</a> returns either a
<a>URL</a> or failure. If they are passed the
algorithm simply modifies the passed <var>url</var> and can terminate without
returning anything.
</div>
<ol>
<li>
<p>If <var>url</var> is not given:
<ol>
<li><p>Set <var>url</var> to a new <a>URL</a>.
<li><p>If leading or trailing <a>ASCII whitespace</a> codepoints are
present in the <var>input</var>:</p>
<ol>
<li><p>Indicate a <a>conformance error</a>.</p></li>
<li><p>Remove leading and trailing <a>ASCII whitespace</a> from
<var>input</var>.<p></li>
</ol>
</ol>
<li><p>If <var>base</var> is not given, set it a new <a>URL</a> with
<code>scheme</code> set to <code>about</code>.
<li><p>If <var>encoding override</var> is not given, set it to
<a>utf-8</a>.
<li>Invoke <code class=grammar-rule><a href=#url>url</a></code>
on the <var>input</var> passing <var>url</var>, <var>base</var> and
<var>encoding override</var>.
<li><p>Return <var>url</var>.
</ol>
Parsing Rules {#parsing-rules}
---
These railroad diagrams, as modified by the accompanying text, define grammar
production rules for URLs. They are to be evaluated sequentially, first
left-to-right then top-to-bottom, backtracking as necessary, until a complete
match against the input provided is found.
Each rule defines a function that can be invoked individually. Rules can
invoke one another.
<dfn title="parse input">Parsing a given input</dfn> according to a railroad
diagram produces a number of intermediate values that can be referenced
individually as local variables within the function. The names of those local
variables isn't specified by this specification, instead the names used in the
railroad diagrams are referenced.
If a given input doesn't match the railroad diagram, failure is returned
instead. If failure is returned by an alternative, evaluation continues
with the next alternative.
The following conventions are used in descriptions of parsing logic for
clarity and conciseness:
* The phrase "<code class=grammar-rule><span>x</span></code>
<dfn>is present</dfn>" is
to be interpreted to mean "the grammar rule for
<code class=grammar-rule><span>x</code><span> matches some part of the
<code>input</code> when that <code>input</code> is parsed according to
the given railroad diagram". Note that if the railroad diagram contains
alternatives where multiple alternatives could potentially match the
input, only the first matching input is considered to be present.
* The phrase "<dfn>value of</dfn>
<code class=grammar-rule><span>x</span></code>" is to be
interpreted to mean "the value returned by the function
<code>x(input)</code> when the function <code>x</code> is passed some
part of the original <code>input</code> during the parsing of that
original <code>input</code> according to the given railroad diagram".
Note: extracting the railroad diagrams from this specification and
interpreting them in isolation will produce incorrect results. In particular,
the definitions provided in the prose modifies these parsing algorithms in
important ways including returning failure and early termination.
<h4 id=rule-url class=no-toc>url(input)</h4>
returns: {
<a href="#concept-url-scheme">scheme</a>,
<a href="#concept-url-scheme-data">scheme-data</a>,
<a href="#concept-url-username">username</a>,
<a href="#concept-url-password">password</a>,
<a href="#concept-url-host">host</a>,
<a href="#concept-url-port">port</a>,
<a href="#concept-url-path">path</a>,
<a href="#concept-url-query">query</a>,
<a href="#concept-url-fragment">fragment</a>
}
<pre class=railroad>
Sequence:
Choice:
N: file-url
N: non-relative-url
N: relative-url
Optional:
Sequence:
T: ?
N: query
Optional:
Sequence:
T: #
N: fragment
</pre>
<ol>
<li><a>Parse <code>input</code></a> according to the above railroad diagram.
<li>Let <code>result</code> be the <a>value of</a> <code class=grammar-rule><a href=#rule-file-url>file-url</a></code>, <code class=grammar-rule><a href=#rule-non-relative-url>non-relative-url</a></code>,
or <code class=grammar-rule><a href=#rule-relative-url>relative-url</a></code> depending on which <a>is present</a>.
<li>If <code class=grammar-rule><a href=#rule-query>query</a></code> <a>is present</a>, set <code>result.query</code> to the <a>value of</a>
<code class=grammar-rule><a href=#rule-query>query</a></code>.
<li>If <code class=grammar-rule><a href=#rule-fragment>fragment</a></code> <a>is present</a>, set <code>result.fragment</code> to the
<a>value of</a> <code class=grammar-rule><a href=#rule-fragment>fragment</a></code>.
<li>If <code>result.scheme</code> has a <a>default port</a>, and if <code>result.port</code> is
equal to that default, then delete the <code>port</code> property from <code>result</code>.
<li>Return <code>result</code>.
</ol>
<h4 id=rule-file-url class=no-toc>file-url(input)</h4>
returns: {
<a href="#concept-url-scheme">scheme</a>,
<a href="#concept-url-host">host</a>,
<a href="#concept-url-path">path</a>
}
<pre class=railroad>
Choice:
Sequence:
T: file
T: :
T: any of [a-zA-Z]
Choice:
T: :
T: |
Optional:
Choice:
T: \
T: /
N: path
Sequence:
ZeroOrMore:
T: /
T: any of [a-zA-Z]
T: |
Optional:
T: /
N: path
Sequence:
T: file
T: :
Optional:
Sequence:
T: /
T: /
N: host
ZeroOrMore:
T: /
N: path
</pre>
<em>"<code><code>file</code></code>" is to be matched case insensitively.</em>
<ol>
<li><a>Parse <code>input</code></a> according to the above railroad diagram.
<li>Let <code>result</code> be an empty object.
<li>Three rows of production rules are defined for files, numbered from top
to bottom. Examples and evaluation instructions for each:
<ol>
<li><div class=example><code>file:c:\foo\bar.html</code></div>
<ol>
<li>Set <code>result.scheme</code> to "<code>file</code>".
<li>Set <code>result.path</code> to the <a>value of</a> <code class=grammar-rule><a href=#rule-path>path</a></code>.
<li>Remove the first element from <code>result.path</code> if it is an empty
string and if there is a second element which has a non-empty value.
<li>Construct a string using the <a>ASCII alpha</a>
following the first "<code>:</code>" in the input
concatenated with a "<code>:</code>". Prepend this string to
<code>result.path</code>.
</ol>
<li><div class=example><code>/C|\foo\bar</code></div>
<ol>
<li>Set <code>result.scheme</code> to "<code>file</code>".
<li>If the <code class=grammar-rule><a href=#rule-host>host</a></code> <a>is present</a>, set <code>result.host</code>
to the <a>value of</a> <code class=grammar-rule><a href=#rule-host>host</a></code>.
<li>If the <code class=grammar-rule><a href=#rule-host>host</a></code> <a title='is present'>is not present</a> and no slashes
precede the <code class=grammar-rule><a href=#rule-path>path</a></code> in the input, then prepend <code>base.path</code>
minus the last element to the <code>result.path</code>.
<li>Set <code>result.path</code> to the <a>value of</a> <code class=grammar-rule><a href=#rule-path>path</a></code>.
</ol>
<li><div class=example><code>file:/example.com/</code></div>
<ol>
<li>Indicate a <a>conformance error</a>.
<li>Set <code>result.scheme</code> to "<code>file</code>".
<li>Set <code>result.path</code> to the <a>value of</a> <code class=grammar-rule><a href=#rule-path>path</a></code>.
<li>Remove the first element from <code>result.path</code> if it is an empty
string and if there is a second element which has a non-empty value.
<li>Construct a string consisting of the code point following
the initial "<code>/</code>" (if any) in the production rule concatenated
with a "<code>:</code>". Prepend this string to the <code>result.path</code> array.
</ol>
</ol>
<li>Return <code>result</code>.
</ol>
<p class=XXX>At the present time, file URLs are generally not
interoperable, and therefore are effectively implementation defined.
Furthermore, the parsing rules in this section have not enjoyed wide review,
and therefore are more likely to be subject to change than other parts of this
specification.
<a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=27518">bug <code>27518</code></a>
proposes to remove all normative definitions for file URLs that are not
known to be interoperable.
<a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=23550">Bug <code>23550</code></a>
and
<a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=23717">bug <code>23717</code></a>
suggest less drastic changes.
<h4 id=rule-non-relative-url class=no-toc>non-relative-url(input)</h4>
returns: {
<a href="#concept-url-scheme">scheme</a>,
<a href="#concept-url-scheme-data">scheme-data</a>
}
<pre class=railroad>
Sequence:
N: scheme
T: :
N: scheme-data
</pre>
<div class=example><code>javascript:alert("Hello, world!");</code></div>
<ol>
<li><a>Parse <code>input</code></a> according to the above railroad diagram.
<li>If the <a>value of</a> <code class=grammar-rule><a href=#rule-scheme>scheme</a></code> does not
match any <a>relative scheme</a> then return failure.
<li>Set <code>encoding override</code> to "<code>utf-<code>8</code></code>".
<li>Initialize <code>result</code> to be a JSON object with <code>scheme</code>
set to be the result returned by <code class=grammar-rule><a href=#rule-scheme>scheme</a></code>, and
<code>schemeData</code> set to the <a>value of</a> <code class=grammar-rule><a href=#rule-scheme-data>scheme-data</a></code>.
<li>Return <code>result</code>.
</ol>
<p class=XXX>The resolution of
<a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=26338">bug <code>26338</code></a>
may change how encoding override is handled.
<p class=XXX>The resolution of
<a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=27233">bug <code>27233</code></a>
may add support for relative URLs for unknown schemes.
<h4 id=rule-relative-url class=no-toc>relative-url(input)</h4>
returns: {
<a href="#concept-url-scheme">scheme</a>,
<a href="#concept-url-username">username</a>,
<a href="#concept-url-password">password</a>,
<a href="#concept-url-host">host</a>,
<a href="#concept-url-port">port</a>,
<a href="#concept-url-path">path</a>
}
<pre class=railroad>
Choice:
Sequence:
Optional:
Sequence:
N: non-file-relative-scheme
T: :
Choice:
T: /
T: \
Choice:
T: /
T: \
N: authority
Optional:
Sequence:
Choice:
T: /
T: \
N: path
Sequence:
N: non-file-relative-scheme
T: :
Optional:
Choice:
T: \
T: /
N: authority
Optional:
Sequence:
Choice:
T: /
T: \
N: path
Sequence:
N: non-file-relative-scheme
T: :
N: path
N: path
</pre>
<ol>
<li><a>Parse <code>input</code></a> according to the above railroad diagram.
<li>Four rows of production rules are defined for relative URLs, numbered
from top to bottom. Examples and evaluation instructions for each:
<ol>
<li><div class=example><code>http://user:[email protected]:<code>21</code>/foo/bar</code></div>
<ol>
<li>If anything other than two forward solidus code points ("<code>//</code>")
immediately follows the first colon in the input, indicate a
<a>conformance error</a>.
<li>Let <code>result</code> be the <a>value of</a> <code class=grammar-rule><a href=#rule-authority>authority</a></code>.
<li>If <code class=grammar-rule><a href=#rule-non-file-relative-scheme>non-file-relative-scheme</a></code> <a>is present</a> in the input, then
set <code>result.scheme</code> to the <a>value of</a> <code class=grammar-rule><a href=#rule-non-file-relative-scheme>non-file-relative-scheme</a></code>.
<li>If <code class=grammar-rule><a href=#rule-non-file-relative-scheme>non-file-relative-scheme</a></code> <a title='is present'>is not present</a>,
then set <code>result.scheme</code> to the value of <code>base.scheme</code>.
<li>If <code class=grammar-rule><a href=#rule-path>path</a></code> <a>is present</a>, set <code>result.path</code> to the <a>value of</a>
<code class=grammar-rule><a href=#rule-path>path</a></code>.
</ol>
<li><div class=example><code>ftp:/example.com/</code> parsed using a base of
<code>http://example.org/foo/bar</code></div>
<ol>
<li>If the <a>value of</a> <code class=grammar-rule><a href=#rule-scheme>scheme</a></code> equals <code>base.scheme</code> then return failure.
<li>Indicate a <a>conformance error</a>.
<li>Let <code>result</code> be the <a>value of</a> <code class=grammar-rule><a href=#rule-authority>authority</a></code>.
<li>Set <code>result.scheme</code> to the <a>value of</a> <code class=grammar-rule><a href=#rule-non-file-relative-scheme>non-file-relative-scheme</a></code>.
<li>If <code>result.host</code> is either an empty string or contains a
colon (<code>U+003A</code>), then terminate parsing with a <a>parse exception</a>.
<li>If <code class=grammar-rule><a href=#rule-path>path</a></code> <a>is present</a>, set <code>result.path</code> to the <a>value of</a>
<code class=grammar-rule><a href=#rule-path>path</a></code>.
</ol>
<li><div class=example><code>http:foo/bar</code></div>
<ol>
<li>Indicate a <a>conformance error</a>.
<li>Let <code>result</code> be an empty object.
<li>Set <code>result.scheme</code> to the <a>value of</a> <code class=grammar-rule><a href=#rule-non-file-relative-scheme>non-file-relative-scheme</a></code>.
<li>Set <code>result.scheme</code> to the <a>value of</a> <code class=grammar-rule><a href=#rule-scheme>scheme</a></code>.
<li>Set <code>result.host</code> to <code>base.host</code>.
<li>Set <code>result.path</code> by the <a>path concatenation</a> of
<code>base.path</code> and <code class=grammar-rule><a href=#rule-path>path</a></code>.
</ol>
<li><div class=example><code>/foo/bar</code></div>
<ol>
<li>Let <code>result</code> be an empty object.
<li>Set <code>result.scheme</code> to <code>base.scheme</code>.
<li>Set <code>result.host</code> to <code>base.host</code>.
<li>if the length of <code class=grammar-rule><a href=#rule-path>path</a></code> is greater than zero, and the first segment
in <code class=grammar-rule><a href=#rule-path>path</a></code> contains a colon (<code>U+003A</code>), indicate a <a>conformance error</a>.
<li>Replace <code>result.path</code> with the <a>path concatenation</a> of <code>base.path</code>
and <code class=grammar-rule><a href=#rule-path>path</a></code>.
</ol>
</ol>
<li>Return <code>result</code>.
</ol>
<h4 id=rule-non-file-relative-scheme class=no-toc>non-file-relative-scheme(input)</h4>
returns: String
<pre class=railroad>
Choice:
T: ftp
T: gopher
T: https
T: http
T: wss
T: ws
</pre>
<em>Schemes are to be matched against the input in a case insensitive
manner.</em>
<ol>
<li><a>Parse <code>input</code></a> according to the above railroad diagram.
<li>Set <code>encoding override</code> to "<code>utf-<code>8</code></code>" if the scheme matches
"<code>wss</code>" or "<code>ws</code>".
<li>Return the scheme as a lowercased string.
</ol>
<p class=XXX>The resolution of
<a href="https://www.w3.org/Bugs/Public/show_bug.cgi?id=26338">bug <code>26338</code></a>
may change how encoding override is handled.
<h4 id=rule-scheme class=no-toc>scheme(input)</h4>
returns: String
<pre class=railroad>
Sequence:
T: any of [a-zA-Z]
ZeroOrMore:
T: any of [-a-zA-Z+.]
</pre>
A scheme consists of an <a>ASCII alpha</a>,
followed by zero or more <a>ASCII alpha</a> or any of the following
code points: hyphen-minus (<code>U+002D</code>), plus sign (<code>U+002B</code>) or full stop
(<code>U+002D</code>).
Return the results as a lowercased string.
<h4 id=rule-authority class=no-toc>authority(input)</h4>
returns: {
<a href="#concept-url-username">username</a>,
<a href="#concept-url-password">password</a>,
<a href="#concept-url-host">host</a>,
<a href="#concept-url-port">port</a>
}
<pre class=railroad>
Sequence:
Optional:
Sequence:
N: user
Optional:
Sequence:
T: :
N: password
T: @
N: host
Optional:
Sequence:
T: :
N: port
</pre>
<ol>
<li><a>Parse <code>input</code></a> according to the above railroad diagram.
<li>Let <code>result</code> be an empty object.
<li>If <code class=grammar-rule><a href=#rule-user>user</a></code> <a>is present</a>, set <code>result.username</code> to the <a>value of</a>
<code class=grammar-rule><a href=#rule-user>user</a></code>.
<li>If <code class=grammar-rule><a href=#rule-password>password</a></code> <a>is present</a>, set <code>result.password</code> to the
<a>value of</a> <code class=grammar-rule><a href=#rule-password>password</a></code>.
<li>Set <code>result.host</code> to the <a>value of</a> <code class=grammar-rule><a href=#rule-host>host</a></code> up to the first "<code>@</code>" sign,
if any. If no "<code>@</code>" signs are present in the <a>value of</a> <code class=grammar-rule><a href=#rule-host>host</a></code>, then
set <code>result.host</code> to the <a>value of</a> <code class=grammar-rule><a href=#rule-host>host</a></code>.
<li>If one or more "<code>@</code>" signs are present in the <a>value of</a> <code class=grammar-rule><a href=#rule-host>host</a></code>,
then perform the following steps:
<ol>
<li>Indicate a <a>conformance error</a>.
<li>Initialize <code>info</code> to the value of "<code>%<code>40</code></code>" plus the remainder of the
<code class=grammar-rule><a href=#rule-host>host</a></code> after the first "<code>@</code>" sign. Replace all remaining "<code>@</code>" signs in
<code>info</code>, with the string "<code>%<code>40</code></code>".
<li>If <code class=grammar-rule><a href=#rule-password>password</a></code> <a>is present</a>, append <code>info</code> to <code>result.password</code>.
<li>If <code class=grammar-rule><a href=#rule-password>password</a></code> <a title="is present">is not present</a> and <code class=grammar-rule><a href=#rule-user>user</a></code>
<a>is present</a>, append <code>info</code> to <code>result.username</code>.
<li>If <code class=grammar-rule><a href=#rule-user>user</a></code> <a title="is present">is not present</a>, set
<code>result.username</code> to <code>info</code>.
</ol>
<li>If <code class=grammar-rule><a href=#rule-port>port</a></code> <a>is present</a>, set <code>result.port</code> to its value.
<li>Return <code>result</code>.
</ol>
<h4 id=rule-user class=no-toc>user(input)</h4>
returns: String
<pre class=railroad>
ZeroOrMore:
T: any except [/\?#@:]
</pre>
Consume all code points until either
a solidus (<code>U+002F</code>),
a reverse solidus (<code>U+005C</code>),
a question mark (<code>U+003F</code>),
a number sign (<code>U+<code>0023</code></code>),
a commercial at (<code>U+<code>0040</code></code>),
a colon (<code>U+003A</code>),
or the end of string is encountered.
Return the <a title=cleanse>cleansed</a> result using the
<a>default encode set</a>.
<h4 id=rule-password class=no-toc>password(input)</h4>
returns: String
<pre class=railroad>
ZeroOrMore:
T: any except [/\?#@]
</pre>
Consume all code points until either
a solidus (<code>U+002F</code>),
a reverse solidus (<code>U+005C</code>),
a question mark (<code>U+003F</code>),
a number sign (<code>U+<code>0023</code></code>),
a commercial at (<code>U+<code>0040</code></code>),
or the end of string is encountered.
Return the <a title=cleanse>cleansed</a> result using the
<a>default encode set</a>.
<h4 id=rule-host class=no-toc>host(input)</h4>
returns: String
<pre class=railroad>
Choice:
Sequence:
N: ipv6addr
Sequence:
N: ipv4addr
ZeroOrMore:
T: any except [:/\?#]
</pre>
<ol>
<li><a>Parse <code>input</code></a> according to the above railroad diagram.
<li>If <code class=grammar-rule><a href=#rule-ipv6addr>ipv6addr</a></code> <a>is present</a>, return the <a>value of</a> <code class=grammar-rule><a href=#rule-ipv6addr>ipv6addr</a></code>.
<li>If <code class=grammar-rule><a href=#rule-ipv4addr>ipv4addr</a></code> <a>is present</a>, return the <a>value of</a> <code class=grammar-rule><a href=#rule-ipv4addr>ipv4addr</a></code>.
<li>Let <code>result</code> be the characters matched by the railroad diagram.
<li>If any <code>U+<code>0009</code></code>, <code>U+000A</code>, <code>U+000D</code>, <code>U+200B</code>, <code>U+<code>2060</code></code>, or <code>U+FEFF</code> code points are
present in <code>result</code>, remove those code points and indicate a
<a>conformance error</a>.
<li>Let <code>domain</code> be the result of
<a href=#concept-host-parser>host parsing</a> <code>result</code>. If this results
in a failure, terminate processing with a <a>parse exception</a>. If <a
href=#concept-host-parser>host parsing</a> returned a value that was
different than what was provided as input, indicate a <a>conformance
error</a>.
<li>Try parsing <code>domain</code> as an <code class=grammar-rule><a href=#rule-ipv4addr>ipv4addr</a></code>. If this succeeds, replace <code>domain</code>
with the result.
<li>Validate <code>domain</code> as follows:
<ol>
<li>split the string at <code>U+002E</code> (full stop) code points
<li>If any of the pieces, other than the first one, are empty strings,
indicate a <a>conformance error</a>.