Fix for Path('0') handling (RT #29334)
Brian Cassidy [Wed, 7 May 2008 17:42:22 +0000 (17:42 +0000)]
Changes
lib/Catalyst.pm
lib/Catalyst/Controller.pm
lib/Catalyst/DispatchType/Path.pm
lib/Catalyst/Dispatcher.pm
t/lib/TestApp/Controller/Root.pm
t/live_component_controller_action_path.t

diff --git a/Changes b/Changes
index 9d92997..66ea77e 100644 (file)
--- a/Changes
+++ b/Changes
@@ -8,6 +8,7 @@
           client disconnected before sending any headers. (Ton Voon)
         - POD fix, IO::FileHandle => IO::Handle (RT #35690)
         - Fix grammar on welcome page (RT #33236)
+        - Fix for Path('0') handling (RT #29334)
 
 5.7012  2007-12-16 23:44:00
         - Fix uri_for()'s and uri_with()'s handling of multibyte chars
index 9e51a9d..749d567 100644 (file)
@@ -1600,7 +1600,8 @@ sub prepare {
     }
 
     my $method  = $c->req->method  || '';
-    my $path    = $c->req->path    || '/';
+    my $path    = $c->req->path;
+    $path       = '/' unless length $path;
     my $address = $c->req->address || '';
 
     $c->log->debug(qq/"$method" request for "$path" from "$address"/)
index ab77e21..b0828ab 100644 (file)
@@ -73,7 +73,7 @@ sub _ACTION : Private {
     my ( $self, $c ) = @_;
     if (   ref $c->action
         && $c->action->can('execute')
-        && $c->req->action )
+        && defined $c->req->action )
     {
         $c->action->dispatch( $c );
     }
@@ -248,7 +248,7 @@ sub _parse_Relative_attr { shift->_parse_Local_attr(@_); }
 
 sub _parse_Path_attr {
     my ( $self, $c, $name, $value ) = @_;
-    $value ||= '';
+    $value = '' if !defined $value;
     if ( $value =~ m!^/! ) {
         return ( 'Path', $value );
     }
index d832dce..d983d8a 100644 (file)
@@ -47,7 +47,7 @@ first action that matches, if any; if not, returns 0.
 sub match {
     my ( $self, $c, $path ) = @_;
 
-    $path ||= '/';
+    $path = '/' if !defined $path;
 
     foreach my $action ( @{ $self->{paths}->{$path} || [] } ) {
         next unless $action->match($c);
index ca5bc25..cd1f57e 100644 (file)
@@ -285,7 +285,7 @@ sub prepare_action {
     s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg for grep { defined } @{$c->req->captures||[]};
 
     $c->log->debug( 'Path is "' . $c->req->match . '"' )
-      if ( $c->debug && $c->req->match );
+      if ( $c->debug && length $c->req->match );
 
     $c->log->debug( 'Arguments are "' . join( '/', @args ) . '"' )
       if ( $c->debug && @args );
@@ -301,7 +301,7 @@ sub get_action {
     my ( $self, $name, $namespace ) = @_;
     return unless $name;
 
-    $namespace = join( "/", grep { length } split '/', $namespace || "" );
+    $namespace = join( "/", grep { length } split '/', ( defined $namespace ? $namespace : "" ) );
 
     return $self->action_hash->{"$namespace/$name"};
 }
index a9cbbda..fc88317 100644 (file)
@@ -6,4 +6,11 @@ __PACKAGE__->config->{namespace} = '';
 
 sub chain_root_index : Chained('/') PathPart('') Args(0) { }
 
+sub zero : Path('0') {
+    my ( $self, $c ) = @_;
+    $c->res->header( 'X-Test-Class' => ref($self) );
+    $c->response->content_type('text/plain; charset=utf-8');
+    $c->forward('TestApp::View::Dump::Request');
+}
+
 1;
index 7b1d0cf..18fc83d 100644 (file)
@@ -10,7 +10,7 @@ our $iters;
 
 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
 
-use Test::More tests => 30*$iters;
+use Test::More tests => 36*$iters;
 use Catalyst::Test 'TestApp';
 
 if ( $ENV{CAT_BENCHMARK} ) {
@@ -124,4 +124,22 @@ sub run_tests {
             'Content is a serialized Catalyst::Request'
         );
     }
+
+    {
+        ok( my $response = request('http://localhost/0'), 'Request' );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is( $response->header('X-Catalyst-Action'),
+            '0', 'Test Action' );
+        is(
+            $response->header('X-Test-Class'),
+            'TestApp::Controller::Root',
+            'Test Class'
+        );
+        like(
+            $response->content,
+            qr/^bless\( .* 'Catalyst::Request' \)$/s,
+            'Content is a serialized Catalyst::Request'
+        );
+    }
 }