Subject: | Incorrect handling ot relative URLs with no path |
Distribution: URI-1.23
ActivePerl v5.6.1 build 635
Windows 98 SE
Code sample and results:
#!perl
use URI;
my $uri = new_abs URI '?query', 'http://www.domain.com/path/script.cgi';
print $uri, "\n";
__END__
output
http://www.domain.com/path/?query
should be
http://www.domain.com/path/script.cgi?query
Fix:
File URI/_generic.pm lines 148 & 149
$p =~ s,[^/]+$,,;
$p .= $path;
to be enclosed in a conditional statement as follows
if (length($path)) {
$p =~ s,[^/]+$,,;
$p .= $path;
}
Diagnosis:
The preceding 'if' statement on line 141 traps the condition
where both the path and the query of the relative URL are
blank, and returns a result for this case immediately.
Subsequent code on lines 148 & 149 assumes that the relative
path is non-blank and strips the resource name from the end
of the path of the base URL, replacing it with the path from
the relative URL. This should happen only if the latter has a
non-blank path to put in its place.
Rob Dixon 10-Apr-2003
rob@dixon.nildram.co.uk