From: Matt S Trout Date: Fri, 19 Nov 2010 15:14:37 +0000 (+0000) Subject: make non-/-terminated path matches allow an extension X-Git-Tag: v0.005~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FWeb-Simple.git;a=commitdiff_plain;h=e7dd1c4b36aca6dffb4272f078966906d4b2f407 make non-/-terminated path matches allow an extension --- diff --git a/lib/Web/Dispatch/Parser.pm b/lib/Web/Dispatch/Parser.pm index ae9aa23..422182c 100644 --- a/lib/Web/Dispatch/Parser.pm +++ b/lib/Web/Dispatch/Parser.pm @@ -134,22 +134,24 @@ sub _url_path_match { my ($self) = @_; for ($_[1]) { my @path; - my $full_path = '$'; + my $end = ''; PATH: while (/\G\//gc) { /\G\.\.\./gc and do { - $full_path = ''; + $end = '(/.*)'; last PATH; }; push @path, $self->_url_path_segment_match($_) or $self->_blam("Couldn't parse path match segment"); } - my $re = '^('.join('/','',@path).')'.($full_path ? '$' : '(/.*)$'); + !$end and length and $_ .= '(?:\.\w+)?' for $path[-1]; + my $re = '^('.join('/','',@path).')'.$end.'$'; $re = qr/$re/; - if ($full_path) { + if ($end) { + return match_path_strip($re); + } else { return match_path($re); } - return match_path_strip($re); } return; } @@ -159,7 +161,7 @@ sub _url_path_segment_match { for ($_[1]) { # trailing / -> require / on end of URL /\G(?:(?=[+|\)])|$)/gc and - return '$'; + return ''; # word chars only -> exact path part match /\G(\w+)/gc and return "\Q$1";