Skip to content

Instantly share code, notes, and snippets.

@dpetrov
Created October 14, 2011 07:02
Show Gist options
  • Save dpetrov/1286444 to your computer and use it in GitHub Desktop.
Save dpetrov/1286444 to your computer and use it in GitHub Desktop.
redirect lc author to uc author
diff --git a/lib/MetaCPAN/Web/Controller/Module.pm b/lib/MetaCPAN/Web/Controller/Module.pm
index 0ef1d03..e01c51d 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/t/controller/module.t b/t/controller/module.t
index 27147a1..be5f9af 100644
--- a/t/controller/module.t
+++ b/t/controller/module.t
@@ -21,6 +21,11 @@ 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, 'redirect 301' );
+
# Moose has ratings, but not all dists do (so be careful what we're testing with)
$tx->like(
'//div[@class="search-bar"]//div[starts-with(@class, "rating-")]/following-sibling::a',
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment