fix root default thingie jayk gave me, sanitize Paths at registration time better
[catagits/Catalyst-Runtime.git] / lib / Catalyst / DispatchType / Path.pm
index 50fbf84..bff5f21 100644 (file)
@@ -74,7 +74,9 @@ sub match {
 
     $path = '/' if !defined $path || !length $path;
 
-    foreach my $action ( @{ $self->_paths->{$path} || [] } ) {
+    my @actions = @{ $self->_paths->{$path} || [] };
+
+    foreach my $action ( @actions ) {
         next unless $action->match($c);
         $c->req->action($path);
         $c->req->match($path);
@@ -114,10 +116,11 @@ sub register_path {
     $path =~ s!^/!!;
     $path = '/' unless length $path;
     $path = URI->new($path)->canonical;
+    $path =~ s{(?<=[^/])/+\z}{};
 
-    unshift( @{ $self->_paths->{$path} ||= [] }, $action);
-
-    $self->_paths->{$path} = [ sort @{ $self->_paths->{$path} } ];
+    $self->_paths->{$path} = [
+        sort { $a <=> $b } ($action, @{ $self->_paths->{$path} || [] })
+    ];
 
     return 1;
 }