From: Brian Cassidy Date: Wed, 7 May 2008 17:42:22 +0000 (+0000) Subject: Fix for Path('0') handling (RT #29334) X-Git-Tag: 5.7099_04~83 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=53119b7876049abfe0d4e4bea5e85724dd4778d7 Fix for Path('0') handling (RT #29334) --- diff --git a/Changes b/Changes index 9d92997..66ea77e 100644 --- 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 diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 9e51a9d..749d567 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -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"/) diff --git a/lib/Catalyst/Controller.pm b/lib/Catalyst/Controller.pm index ab77e21..b0828ab 100644 --- a/lib/Catalyst/Controller.pm +++ b/lib/Catalyst/Controller.pm @@ -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 ); } diff --git a/lib/Catalyst/DispatchType/Path.pm b/lib/Catalyst/DispatchType/Path.pm index d832dce..d983d8a 100644 --- a/lib/Catalyst/DispatchType/Path.pm +++ b/lib/Catalyst/DispatchType/Path.pm @@ -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); diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index ca5bc25..cd1f57e 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -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"}; } diff --git a/t/lib/TestApp/Controller/Root.pm b/t/lib/TestApp/Controller/Root.pm index a9cbbda..fc88317 100644 --- a/t/lib/TestApp/Controller/Root.pm +++ b/t/lib/TestApp/Controller/Root.pm @@ -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; diff --git a/t/live_component_controller_action_path.t b/t/live_component_controller_action_path.t index 7b1d0cf..18fc83d 100644 --- a/t/live_component_controller_action_path.t +++ b/t/live_component_controller_action_path.t @@ -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' + ); + } }