Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Redo fix for #8, respecting the index matches without allow_path_info

Signed-off-by: Pedro Melo <melo@simplicidade.org>
  • Loading branch information...
commit 2a586801c0989659e91a00629e2ba5f5054cd4ba 1 parent 06a6c25
@melo authored
Showing with 24 additions and 2 deletions.
  1. +6 −2 lib/Mason/Interp.pm
  2. +18 −0 lib/Mason/t/ResolveURI.pm
View
8 lib/Mason/Interp.pm
@@ -475,11 +475,14 @@ method _build_match_request_path ($interp:) {
my ( $request, $request_path ) = @_;
my $interp = $request->interp;
my $path_info = '';
+ my $trailing_slash = '';
my $declined_paths = $request->declined_paths;
my @index_subpaths = map { "/$_" } @index_names;
my $path = $request_path;
my @tried_paths;
+ $trailing_slash = chop($path) if $path ne '/' && substr($path, -1) eq '/';
+
while (1) {
my @candidate_paths =
( $path_info eq '' && !@autoextensions ) ? ($path)
@@ -492,13 +495,14 @@ method _build_match_request_path ($interp:) {
foreach my $candidate_path (@candidate_paths) {
next if $declined_paths->{$candidate_path};
if ( my $compc = $interp->load($candidate_path) ) {
+ my $path_info_ok = $compc->cmeta->is_dhandler || $compc->allow_path_info;
if (
$compc->cmeta->is_top_level
&& ( $path_info eq ''
- || $compc->cmeta->is_dhandler
- || $compc->allow_path_info )
+ || $path_info_ok )
)
{
+ $path_info .= $trailing_slash if $path_info_ok;
$request->{path_info} = $path_info;
return $compc->cmeta->path;
}
View
18 lib/Mason/t/ResolveURI.pm
@@ -89,6 +89,24 @@ sub test_resolve : Tests {
$try->( $run_path, [ '/foo/bar/baz/index2', '/foo/bar/baz/index' ], '/foo/bar/baz/index', '' );
$try->( '/foo', [ '/foo/index' ], '/foo/index', '' );
$try->( '/foo/', [ '/foo/index' ], '/foo/index', '' );
+
+ # trailing slashes + path_info
+ $try->( '/foo', ['/foo.mc=1'], '/foo.mc', '' );
+ $try->( '/foo/', ['/foo.mc=1'], '/foo.mc', '/' );
+ $try->( '/foo/bar', ['/foo.mc=1'], '/foo.mc', 'bar' );
+ $try->( '/foo/bar/', ['/foo.mc=1'], '/foo.mc', 'bar/' );
+ $try->( '/foo/', ['/foo.mc'], '/foo.mc', '' );
+ @interp_params = ( dhandler_names => ['dhandler'] );
+ $try->( '/foo/', ['/foo/dhandler'], '/foo/dhandler', '/' );
+ $try->( '/foo/bar', ['/foo/dhandler'], '/foo/dhandler', 'bar' );
+ $try->( '/foo/bar/', ['/foo/dhandler'], '/foo/dhandler', 'bar/' );
+ @interp_params = ( index_names => ['index'] );
+ $try->( '/foo/', ['/foo/index=1'], '/foo/index', '/' );
+ @interp_params = ( dhandler_names => ['dhandler'], index_names => ['index'] );
+ $try->( '/foo/', ['/foo/dhandler', '/foo/index'], '/foo/index', '' );
+ $try->( '/foo/', ['/foo/dhandler', '/foo/index=1'], '/foo/index', '/' );
+ $try->( '/foo/more', ['/foo/dhandler', '/foo/index'], '/foo/dhandler', 'more' );
+ $try->( '/foo/more', ['/foo/dhandler', '/foo/index=1'], '/foo/dhandler', 'more' );
}
sub test_decline : Tests {
Please sign in to comment.
Something went wrong with that request. Please try again.