From: Christian Walde Date: Thu, 8 Dec 2011 23:03:31 +0000 (+0100) Subject: allow subdispatch to apply even when the url has no trailing slash X-Git-Tag: v0.012~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8c51c01a7b84bfb5afcd04f15879fbc77f026f1b;hp=c2cf05341169b1a51b3b5c00f41eaf0e02862774;p=catagits%2FWeb-Simple.git allow subdispatch to apply even when the url has no trailing slash --- diff --git a/lib/Web/Dispatch/Parser.pm b/lib/Web/Dispatch/Parser.pm index e3ea504..d77d418 100644 --- a/lib/Web/Dispatch/Parser.pm +++ b/lib/Web/Dispatch/Parser.pm @@ -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; diff --git a/t/dispatch_parser.t b/t/dispatch_parser.t index b1bc859..dfaa026 100644 --- a/t/dispatch_parser.t +++ b/t/dispatch_parser.t @@ -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' ],