Handle "0" as a path
[catagits/Catalyst-Runtime.git] / lib / Catalyst.pm
index ab4c3f0..c290789 100644 (file)
@@ -24,7 +24,7 @@ use Tree::Simple qw/use_weak_refs/;
 use Tree::Simple::Visitor::FindByUID;
 use attributes;
 use utf8;
-use Carp qw/croak/;
+use Carp qw/croak carp/;
 
 BEGIN { require 5.008001; }
 
@@ -932,7 +932,7 @@ sub uri_for {
     # massage namespace, empty if absolute path
     $namespace =~ s/^\/// if $namespace;
     $namespace .= '/' if $namespace;
-    $path ||= '';
+    $path = '' if !defined $path;
     $namespace = '' if $path =~ /^\//;
     $path =~ s/^\///;
     $path =~ s/\?/%3F/g;
@@ -949,8 +949,14 @@ sub uri_for {
     };
     
     # join args with '/', or a blank string
-    my $args = ( scalar @args ? '/' . join( '/', map {s/\?/%3F/g; $_} @args ) : '' );
-    $args =~ s/^\/// unless $path;
+    my $args = ( scalar @args ? '/' . join( '/', map {
+            unless (defined) {
+               carp "uri_for called with undefined argument";
+               $_='';
+            }
+            s/\?/%3F/g; $_
+        } @args ) : '' );
+    $args =~ s/^\/// unless length $path;
     my $res =
       URI->new_abs( URI->new_abs( "$path$args", "$basepath$namespace" ), $base )
       ->canonical;
@@ -1399,7 +1405,7 @@ sub finalize_headers {
         if ( !$c->response->body ) {
             # Add a default body if none is already present
             $c->response->body(
-                "<p>This item has moved <a href=\"$location\">here</a>.</p>"
+                qq{<html><body><p>This item has moved <a href="$location">here</a>.</p></body></html>}
             );
         }
     }