Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #366 from dpetrov/master

force consistent casing in URLs && add HTML::Restrict to Prereqs
  • Loading branch information...
commit 9f9e255c3920ec8ff87c088c62df4ba13e90549e 2 parents 1fe9035 + 17b753b
@oalders oalders authored
View
1  dist.ini
@@ -38,6 +38,7 @@ Template::Plugin::Markdown = 0
Template::Plugin::Number::Format = 0
Template::Plugin::Page = 0
XML::Feed = 0
+HTML::Restrict = 0
[Prereqs / TestRequires]
Test::More = 0.96
Test::XPath = 0.15
View
10 lib/MetaCPAN/Web/Controller/Module.pm
@@ -11,7 +11,15 @@ with qw(
);
sub index : PathPart('module') : Chained('/') : Args {
- my ( $self, $c, @module ) = @_;
+ my ( $self, $c, $id, @module ) = @_;
+
+ # force consistent casing in URLs
+ if ( @module != 0 and $id ne uc($id) ) {
+ $c->res->redirect('/module/' . join('/', uc($id), @module), 301);
+ $c->detach();
+ }
+
+ @module = ($id, @module);
my $data
= @module == 1
? $c->model('API::Module')->find(@module)->recv
View
6 lib/MetaCPAN/Web/Controller/Release.pm
@@ -14,6 +14,12 @@ sub index : PathPart('release') : Chained('/') : Args {
my ( $self, $c, $author, $release ) = @_;
my $model = $c->model('API::Release');
+ # force consistent casing in URLs
+ if ( $author && $release && $author ne uc($author) ) {
+ $c->res->redirect("/release/" . uc($author) . "/$release", 301);
+ $c->detach();
+ }
+
my $data
= $author && $release
? $model->get( $author, $release )
View
2  t/controller/author.t
@@ -8,6 +8,8 @@ test_psgi app, sub {
ok( my $res = $cb->( GET "/author/DOESNTEXIST" ),
'GET /author/DOESNTEXIST' );
is( $res->code, 404, 'code 404' );
+ ok( $res = $cb->( GET "/author/perler" ), 'GET /author/perler' );
+ is( $res->code, 301, 'code 301' );
ok( $res = $cb->( GET "/author/PERLER" ), 'GET /author/PERLER' );
is( $res->code, 200, 'code 200' );
my $tx = tx($res);
View
4 t/controller/module.t
@@ -21,6 +21,10 @@ test_psgi app, sub {
ok( $res = $cb->( GET $this ), "GET $this" );
is($latest, $res->content, 'content of both urls is exactly the same');
+ # get module with lc author
+ $this =~ s{(/module/.*?/)}{lc($1)}e; # lc author name
+ ok( $res = $cb->( GET $this ), "GET $this" );
+ is( $res->code, 301, 'code 301' );
};
done_testing;
View
4 t/controller/release.t
@@ -34,6 +34,10 @@ test_psgi app, sub {
'content of both urls is exactly the same'
);
+ # get module with lc author
+ $this =~ s{(/release/.*?/)}{lc($1)}e; # lc author name
+ ok( $res = $cb->( GET $this ), "GET $this" );
+ is( $res->code, 301, 'code 301' );
};
done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.