I would expect $uri->abs(0) and $uri->abs("") to behave the same way as
for example $uri->abs("foo"), instead of misleadingly croaking about a
missing base argument. Patch including a test case and a fix attached.
Index: URI/_generic.pm
===================================================================
RCS file: /cvsroot/libwww-perl/uri/URI/_generic.pm,v
retrieving revision 1.19
diff -a -u -r1.19 _generic.pm
--- URI/_generic.pm 23 Jul 2003 23:45:54 -0000 1.19
+++ URI/_generic.pm 22 Aug 2004 19:58:52 -0000
@@ -124,7 +124,8 @@
sub abs
{
my $self = shift;
- my $base = shift || Carp::croak("Missing base argument");
+ defined(my $base = shift) ||
+ Carp::croak("Base argument for abs() not defined");
if (my $scheme = $self->scheme) {
return $self unless $URI::ABS_ALLOW_RELATIVE_SCHEME;
Index: t/abs.t
===================================================================
RCS file: /cvsroot/libwww-perl/uri/t/abs.t,v
retrieving revision 1.5
diff -a -u -r1.5 abs.t
--- t/abs.t 5 Aug 2003 15:27:48 -0000 1.5
+++ t/abs.t 22 Aug 2004 19:58:52 -0000
@@ -1,6 +1,6 @@
#!perl -w
-print "1..45\n";
+print "1..49\n";
# This test the resolution of abs path for all examples given
# in the "Uniform Resource Identifiers (URI): Generic Syntax" document.
@@ -44,6 +44,15 @@
print "ok ", $testno++, "\n";
}
+for my $u (qw(foo/bar http://localhost/foo/bar.html)) {
+ my $a = URI->new($u);
+ my $b = $a->abs("quux");
+ for my $c (0, "") {
+ print "not " unless $a->abs($c) eq $b;
+ print "ok ", $testno++, "\n";
+ }
+}
+
if (@rel_fail) {
print "\n\nIn the following cases we did not get back to where we started with rel()\n";
print @rel_fail;