Skip to content

Instantly share code, notes, and snippets.

@dpetrov
Created October 14, 2011 07:21
Show Gist options
  • Save dpetrov/1286463 to your computer and use it in GitHub Desktop.
Save dpetrov/1286463 to your computer and use it in GitHub Desktop.
diff --git a/lib/MetaCPAN/Web/Controller/Module.pm b/lib/MetaCPAN/Web/Controller/Module.pm
index 0ef1d03..27a7be6 100644
--- a/lib/MetaCPAN/Web/Controller/Module.pm
+++ b/lib/MetaCPAN/Web/Controller/Module.pm
@@ -6,7 +6,15 @@ use namespace::autoclean;
BEGIN { extends 'MetaCPAN::Web::Controller' }
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
diff --git a/lib/MetaCPAN/Web/Controller/Release.pm b/lib/MetaCPAN/Web/Controller/Release.pm
index 63bb114..c66872d 100644
--- a/lib/MetaCPAN/Web/Controller/Release.pm
+++ b/lib/MetaCPAN/Web/Controller/Release.pm
@@ -10,6 +10,11 @@ sub index : PathPart('release') : Chained('/') : Args {
my ( $self, $c, $author, $release ) = @_;
my $model = $c->model('API::Release');
+ 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 )
diff --git a/t/controller/author.t b/t/controller/author.t
index 1d11384..800ecb1 100644
--- a/t/controller/author.t
+++ b/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);
diff --git a/t/controller/module.t b/t/controller/module.t
index 27147a1..7f646e9 100644
--- a/t/controller/module.t
+++ b/t/controller/module.t
@@ -34,6 +34,10 @@ test_psgi app, sub {
'cpanratings link to rate this dist'
);
+ # 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;
diff --git a/t/controller/release.t b/t/controller/release.t
index 376e71f..1ea5da2 100644
--- a/t/controller/release.t
+++ b/t/controller/release.t
@@ -53,6 +53,10 @@ test_psgi app, sub {
'cpanratings link to rate this dist'
);
+ # 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment