5 # This test the resolution of abs path for all examples given
6 # in the "Uniform Resource Identifiers (URI): Generic Syntax" document.
9 $base = "http://a/b/c/d;p?q";
13 #next if 1 .. /^C\.\s+/;
15 next unless /\s+(\S+)\s*=\s*(.*)/;
18 $expect =~ s/\(current document\)/$base/;
19 #print "$uref => $expect\n";
22 my $u = URI->new($uref, $base);
23 if ($u->abs($base)->as_string ne $expect) {
25 my $abs = $u->abs($base)->as_string;
26 print qq(URI->new("$uref")->abs("$base") ==> "$abs"\n);
29 # Let's test another version of the same thing
31 my $b = URI->new($base);
32 if ($u->abs($b,1) ne $expect && $uref !~ /^http:/) {
34 print qq(URI->new("$uref")->abs(URI->new("$base"), 1)\n);
37 # Let's try the other way
38 $u = URI->new($expect)->rel($base)->as_string;
40 push(@rel_fail, qq($testno: URI->new("$expect", "$base")->rel ==> "$u" (not "$uref")\n));
44 print "ok ", $testno++, "\n";
48 print "\n\nIn the following cases we did not get back to where we started with rel()\n";
56 Network Working Group T. Berners-Lee, MIT/LCS
57 INTERNET-DRAFT R. Fielding, U.C. Irvine
58 draft-fielding-uri-syntax-02 L. Masinter, Xerox Corporation
59 Expires six months after publication date March 4, 1998
62 Uniform Resource Identifiers (URI): Generic Syntax
66 C. Examples of Resolving Relative URI References
68 Within an object with a well-defined base URI of
72 the relative URIs would be resolved as follows:
82 ?y = http://a/b/c/d;p?y
83 g?y = http://a/b/c/g?y
84 #s = (current document)#s
85 g#s = http://a/b/c/g#s
86 g?y#s = http://a/b/c/g?y#s
88 g;x = http://a/b/c/g;x
89 g;x?y#s = http://a/b/c/g;x?y#s
99 C.2. Abnormal Examples
101 Although the following abnormal examples are unlikely to occur in
102 normal practice, all URI parsers should be capable of resolving them
103 consistently. Each example uses the same base as above.
105 An empty reference refers to the start of the current document.
107 <> = (current document)
109 Parsers must be careful in handling the case where there are more
110 relative path ".." segments than there are hierarchical levels in
111 the base URI's path. Note that the ".." syntax cannot be used to
112 change the authority component of a URI.
114 ../../../g = http://a/../g
115 ../../../../g = http://a/../../g
117 In practice, some implementations strip leading relative symbolic
118 elements (".", "..") after applying a relative URI calculation, based
119 on the theory that compensating for obvious author errors is better
120 than allowing the request to fail. Thus, the above two references
121 will be interpreted as "http://a/g" by some implementations.
123 Similarly, parsers must avoid treating "." and ".." as special when
124 they are not complete components of a relative path.
127 /../g = http://a/../g
130 g.. = http://a/b/c/g..
131 ..g = http://a/b/c/..g
133 Less likely are cases where the relative URI uses unnecessary or
134 nonsensical forms of the "." and ".." complete path segments.
136 ./../g = http://a/b/g
137 ./g/. = http://a/b/c/g/
138 g/./h = http://a/b/c/g/h
139 g/../h = http://a/b/c/h
140 g;x=1/./y = http://a/b/c/g;x=1/y
141 g;x=1/../y = http://a/b/c/y
143 All client applications remove the query component from the base URI
144 before resolving relative URIs. However, some applications fail to
145 separate the reference's query and/or fragment components from a
146 relative path before merging it with the base path. This error is
147 rarely noticed, since typical usage of a fragment never includes the
148 hierarchy ("/") character, and the query component is not normally
149 used within relative references.
151 g?y/./x = http://a/b/c/g?y/./x
152 g?y/../x = http://a/b/c/g?y/../x
153 g#s/./x = http://a/b/c/g#s/./x
154 g#s/../x = http://a/b/c/g#s/../x
156 Some parsers allow the scheme name to be present in a relative URI
157 if it is the same as the base URI scheme. This is considered to be
158 a loophole in prior specifications of partial URIs [RFC1630]. Its
159 use should be avoided.
165 ==========================================================================
167 Some extra tests for good measure...
169 #foo? = (current document)#foo?
170 ?#foo = http://a/b/c/d;p?#foo