From: Rafael Kitover Date: Sun, 21 Jun 2009 00:26:22 +0000 (+0000) Subject: fix root default thingie jayk gave me, sanitize Paths at registration time better X-Git-Tag: 5.80006~41 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=5299fff8fe52a4f4c10698b258984e41a2f6964f fix root default thingie jayk gave me, sanitize Paths at registration time better --- diff --git a/lib/Catalyst/DispatchType/Default.pm b/lib/Catalyst/DispatchType/Default.pm index d90ff57..a642eea 100644 --- a/lib/Catalyst/DispatchType/Default.pm +++ b/lib/Catalyst/DispatchType/Default.pm @@ -41,7 +41,7 @@ other possibilities have been exhausted. sub match { my ( $self, $c, $path ) = @_; - return if $path =~ m!/!; # Not at root yet, wait for it ... + return if $path ne ''; # Not at root yet, wait for it ... my $result = ( $c->get_actions( 'default', $c->req->path ) )[-1]; # Find default on namespace or super diff --git a/lib/Catalyst/DispatchType/Path.pm b/lib/Catalyst/DispatchType/Path.pm index 5c1e4ed..bff5f21 100644 --- a/lib/Catalyst/DispatchType/Path.pm +++ b/lib/Catalyst/DispatchType/Path.pm @@ -116,6 +116,7 @@ sub register_path { $path =~ s!^/!!; $path = '/' unless length $path; $path = URI->new($path)->canonical; + $path =~ s{(?<=[^/])/+\z}{}; $self->_paths->{$path} = [ sort { $a <=> $b } ($action, @{ $self->_paths->{$path} || [] }) diff --git a/lib/Catalyst/Dispatcher.pm b/lib/Catalyst/Dispatcher.pm index 08a4248..680a76b 100644 --- a/lib/Catalyst/Dispatcher.pm +++ b/lib/Catalyst/Dispatcher.pm @@ -370,9 +370,7 @@ sub prepare_action { DESCEND: while (@path) { $path = join '/', @path; - $path =~ s#^/##; - - $path = '' if $path eq '/'; # Root action + $path =~ s#^/+##; # Check out dispatch types to see if any will handle the path at # this level @@ -459,9 +457,6 @@ sub get_containers { } return reverse grep { defined } @containers, $self->_container_hash->{''}; - - #return (split '/', $namespace); # isnt this more clear? - my @parts = split '/', $namespace; } =head2 $self->uri_for_action($action, \@captures) diff --git a/t/aggregate/live_component_controller_action_index_or_default.t b/t/aggregate/live_component_controller_action_index_or_default.t index fada74b..e10d6d2 100644 --- a/t/aggregate/live_component_controller_action_index_or_default.t +++ b/t/aggregate/live_component_controller_action_index_or_default.t @@ -10,7 +10,7 @@ our $iters; BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; } -use Test::More tests => 3*$iters; +use Test::More tests => 6*$iters; use Catalyst::Test 'TestAppIndexDefault'; @@ -27,5 +27,14 @@ else { sub run_tests { is(get('/indexchained'), 'index_chained', ':Chained overrides index'); is(get('/indexprivate'), 'index_private', 'index : Private still works'); + +# test :Path overriding default is(get('/one_arg'), 'path_one_arg', ':Path overrides default'); + is(get('/one_arg/foo/bar'), 'default', 'default still works'); + +# now the same thing with a namespace, and a trailing / on the :Path + is(get('/default/one_arg'), 'default_path_one_arg', + ':Path overrides default'); + is(get('/default/one_arg/foo/bar'), 'default_default', + 'default still works'); }