allow subdispatch to apply even when the url has no trailing slash
Christian Walde [Thu, 8 Dec 2011 23:03:31 +0000 (00:03 +0100)]
lib/Web/Dispatch/Parser.pm
t/dispatch_parser.t

index e3ea504..d77d418 100644 (file)
@@ -138,6 +138,11 @@ sub _url_path_match {
         };
       push @path, $self->_url_path_segment_match($_)
         or $self->_blam("Couldn't parse path match segment");
+      /\G\.\.\./gc
+        and do {
+          $end = '(.*)';
+          last PATH;
+        };
       /\G\.\*/gc
         and do {
           $keep_dot = 1;
index b1bc859..dfaa026 100644 (file)
@@ -308,6 +308,29 @@ my $dp = Web::Dispatch::Parser->new;
 }
 
 {
+  my $match = '/foo...';
+  my $sub = $dp->parse($match);
+
+  is_deeply(
+    [ $sub->({ PATH_INFO => '/foo/bar' }) ],
+    [ { PATH_INFO => '/bar', SCRIPT_NAME => '/foo' } ],
+    "$match matches /foo/bar and strips to /bar"
+  );
+
+  is_deeply(
+    [ $sub->({ PATH_INFO => '/foo/' }) ],
+    [ { PATH_INFO => '/', SCRIPT_NAME => '/foo' } ],
+    "$match matches /foo/ and strips to /"
+  );
+
+  is_deeply(
+    [ $sub->({ PATH_INFO => '/foo' }) ],
+    [ { PATH_INFO => '', SCRIPT_NAME => '/foo' } ],
+    "$match matches /foo and strips to empty path"
+  );
+}
+
+{
   my @dot_pairs = (
     [ '/one/*' => 'two' ],
     [ '/one/*.*' => 'two.three' ],