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
|
<HTML><HEAD>
<TITLE>Examples of Resolving Relative URLs</TITLE>
<BASE href="http://a/b/c/d;p?q">
</HEAD><BODY>
<H1>Examples of Resolving Relative URLs</H1>
This document has an embedded base URL of
<PRE>
Content-Base: http://a/b/c/d;p?q
</PRE>
the relative URLs should be resolved as shown below.
<P>
I will need your help testing the examples on multiple browsers.
What you need to do is point to the example anchor and compare it to the
resolved URL in your browser (most browsers have a feature by which you
can see the resolved URL at the bottom of the window/screen when the anchor
is active).
<H2>Tested Clients and Client Libraries</H2>
<DL COMPACT>
<DT>[R]
<DD>RFC 2396 (the right way to parse)
<DT>[X]
<DD>RFC 1808
<DT>[1]
<DD>Mozilla/4.03 [en] (X11; U; SunOS 5.5 sun4u; Nav)
<DT>[2]
<DD>Lynx/2.7.1 libwww-FM/2.14
<DT>[3]
<DD>MSIE 3.01; Windows 95
<DT>[4]
<DD>NCSA_Mosaic/2.6 (X11;SunOS 4.1.2 sun4m) libwww/2.12
<DT>[5]
<DD>libwww-perl/5.14 [Martijn Koster]
</DL>
<H2>Normal Examples</H2>
<PRE>
RESULTS from
<a href="g:h">g:h</a> = g:h [R,X,2,3,4,5]
http://a/b/c/g:h [1]
<a href="g">g</a> = http://a/b/c/g [R,X,1,2,3,4,5]
<a href="./g">./g</a> = http://a/b/c/g [R,X,1,2,3,4,5]
<a href="g/">g/</a> = http://a/b/c/g/ [R,X,1,2,3,4,5]
<a href="/g">/g</a> = http://a/g [R,X,1,2,3,4,5]
<a href="//g">//g</a> = http://g [R,X,1,2,3,4,5]
<a href="?y">?y</a> = http://a/b/c/?y [R,1,2,3,4]
http://a/b/c/d;p?y [X,5]
<a href="g?y">g?y</a> = http://a/b/c/g?y [R,X,1,2,3,4,5]
<a name="s" href="#s">#s</a> = (current document)#s [R,2,4]
http://a/b/c/d;p?q#s [X,1,3,5]
<a href="g#s">g#s</a> = http://a/b/c/g#s [R,X,1,2,3,4,5]
<a href="g?y#s">g?y#s</a> = http://a/b/c/g?y#s [R,X,1,2,3,4,5]
<a href=";x">;x</a> = http://a/b/c/;x [R,1,2,3,4]
http://a/b/c/d;x [X,5]
<a href="g;x">g;x</a> = http://a/b/c/g;x [R,X,1,2,3,4,5]
<a href="g;x?y#s">g;x?y#s</a> = http://a/b/c/g;x?y#s [R,X,1,2,3,4,5]
<a href=".">.</a> = http://a/b/c/ [R,X,2,5]
http://a/b/c/. [1]
http://a/b/c [3,4]
<a href="./">./</a> = http://a/b/c/ [R,X,1,2,3,4,5]
<a href="..">..</a> = http://a/b/ [R,X,2,5]
http://a/b [1,3,4]
<a href="../">../</a> = http://a/b/ [R,X,1,2,3,4,5]
<a href="../g">../g</a> = http://a/b/g [R,X,1,2,3,4,5]
<a href="../..">../..</a> = http://a/ [R,X,2,5]
http://a [1,3,4]
<a href="../../">../../</a> = http://a/ [R,X,1,2,3,4,5]
<a href="../../g">../../g</a> = http://a/g [R,X,1,2,3,4,5]
</PRE>
<H2>Abnormal Examples</H2>
Although the following abnormal examples are unlikely to occur in
normal practice, all URL parsers should be capable of resolving them
consistently. Each example uses the same base as above.<P>
An empty reference refers to the start of the current document.
<PRE>
<a href=""><></a> = (current document) [R,2,4]
http://a/b/c/d;p?q [X,3,5]
http://a/b/c/ [1]
</PRE>
Parsers must be careful in handling the case where there are more
relative path ".." segments than there are hierarchical levels in the
base URL's path. Note that the ".." syntax cannot be used to change
the site component of a URL.
<PRE>
<a href="../../../g">../../../g</a> = http://a/../g [R,X,2,4,5]
http://a/g [R,1,3]
<a href="../../../../g">../../../../g</a> = http://a/../../g [R,X,2,4,5]
http://a/g [R,1,3]
</PRE>
In practice, some implementations strip leading relative symbolic
elements (".", "..") after applying a relative URL calculation, based
on the theory that compensating for obvious author errors is better
than allowing the request to fail. Thus, the above two references
will be interpreted as "http://a/g" by some implementations.
<P>
Similarly, parsers must avoid treating "." and ".." as special when
they are not complete components of a relative path.
<PRE>
<a href="/./g">/./g</a> = http://a/./g [R,X,2,3,4,5]
http://a/g [1]
<a href="/../g">/../g</a> = http://a/../g [R,X,2,3,4,5]
http://a/g [1]
<a href="g.">g.</a> = http://a/b/c/g. [R,X,1,2,3,4,5]
<a href=".g">.g</a> = http://a/b/c/.g [R,X,1,2,3,4,5]
<a href="g..">g..</a> = http://a/b/c/g.. [R,X,1,2,3,4,5]
<a href="..g">..g</a> = http://a/b/c/..g [R,X,1,2,3,4,5]
</PRE>
Less likely are cases where the relative URL uses unnecessary or
nonsensical forms of the "." and ".." complete path segments.
<PRE>
<a href="./../g">./../g</a> = http://a/b/g [R,X,1,2,5]
http://a/b/c/../g [3,4]
<a href="./g/.">./g/.</a> = http://a/b/c/g/ [R,X,2,5]
http://a/b/c/g/. [1]
http://a/b/c/g [3,4]
<a href="g/./h">g/./h</a> = http://a/b/c/g/h [R,X,1,2,3,4,5]
<a href="g/../h">g/../h</a> = http://a/b/c/h [R,X,1,2,3,4,5]
<a href="g;x=1/./y">g;x=1/./y</a> = http://a/b/c/g;x=1/y [R,1,2,3,4]
http://a/b/c/g;x=1/./y [X,5]
<a href="g;x=1/../y">g;x=1/../y</a> = http://a/b/c/y [R,1,2,3,4]
http://a/b/c/g;x=1/../y [X,5]
</PRE>
All client applications remove the query component from the base URL
before resolving relative URLs. However, some applications fail to
separate the reference's query and/or fragment components from a
relative path before merging it with the base path. This error is
rarely noticed, since typical usage of a fragment never includes the
hierarchy ("/") character, and the query component is not normally
used within relative references.
<PRE>
<a href="g?y/./x">g?y/./x</a> = http://a/b/c/g?y/./x [R,X,5]
http://a/b/c/g?y/x [1,2,3,4]
<a href="g?y/../x">g?y/../x</a> = http://a/b/c/g?y/../x [R,X,5]
http://a/b/c/x [1,2,3,4]
<a href="g#s/./x">g#s/./x</a> = http://a/b/c/g#s/./x [R,X,2,3,4,5]
http://a/b/c/g#s/x [1]
<a href="g#s/../x">g#s/../x</a> = http://a/b/c/g#s/../x [R,X,2,3,4,5]
http://a/b/c/x [1]
</PRE>
Some parsers allow the scheme name to be present in a relative URI if
it is the same as the base URI scheme. This is considered to be a
loophole in prior specifications of partial URI [RFC1630]. Its use
should be avoided.
<PRE>
<a href="http:g">http:g</a> = http:g [R,X,5]
| http://a/b/c/g [1,2,3,4] (ok for compat.)
<a href="http:">http:</a> = http: [R,X,5]
http://a/b/c/ [1]
http://a/b/c/d;p?q [2,3,4]
</PRE>
</BODY></HTML>
|