Skip to content

Commit

Permalink
Return 404 for invalid paths, e.g. /release//File-Stat-Convert instea…
Browse files Browse the repository at this point in the history
…d of a 500 - fix #3155
  • Loading branch information
ranguard committed Aug 24, 2024
1 parent 9059e9d commit 1ff24a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/MetaCPAN/Web/Controller/Release.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ sub release_view : Chained('root') PathPart('') Args(0) {
my ( $self, $c ) = @_;
my ( $author, $release ) = $c->stash->@{qw(author_name release_name)};

$c->stash(
permalinks => 1,
release_info => $c->model( 'ReleaseInfo', full_details => 1 )
->get( $author, $release ),
);
if ( !$author ) {
# /release//File-Stat-Convert and others are never going to match
# do not even try call the API
$c->detach('/not_found');
} else {
$c->stash(
permalinks => 1,
release_info => $c->model( 'ReleaseInfo', full_details => 1 )
->get( $author, $release ),
);
}
$c->forward('view');
}

Expand Down
8 changes: 8 additions & 0 deletions t/controller/release.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ test_psgi app, sub {
ok( $res = $cb->( GET '/dist/Moose' ), 'GET /dist/Moose' );
is( $res->code, 200, 'code 200' );


ok( $res = $cb->( GET '/release/BRICAS/CPAN-Changes-0.21' ), 'GET /release/BRICAS/CPAN-Changes-0.21' );
is( $res->code, 200, 'code 200' );

# Testing missing author returns 404 not a 500
ok( $res = $cb->( GET '/release//CPAN-Changes-0.21' ), 'GET /release//CPAN-Changes-0.21' );
is( $res->code, 404, 'code 404' );

my $tx = tx($res);
$tx->like( '/html/head/title', qr/Moose/, 'title includes Moose' );
ok( $tx->find_value('//a[@href="/dist/Moose"]'),
Expand Down

0 comments on commit 1ff24a0

Please sign in to comment.