Skip to content

Commit

Permalink
Redo fix for jonswar#8, respecting the index matches without allow_pa…
Browse files Browse the repository at this point in the history
…th_info

Signed-off-by: Pedro Melo <melo@simplicidade.org>
  • Loading branch information
melo committed Jan 7, 2013
1 parent 06a6c25 commit 2a58680
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/Mason/Interp.pm
Expand Up @@ -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)
Expand All @@ -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;
}
Expand Down
18 changes: 18 additions & 0 deletions lib/Mason/t/ResolveURI.pm
Expand Up @@ -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 {
Expand Down

0 comments on commit 2a58680

Please sign in to comment.