diff --git a/lib/MetaCPAN/Web/Controller/Search.pm b/lib/MetaCPAN/Web/Controller/Search.pm index ddbbf96952..a69560f0f3 100644 --- a/lib/MetaCPAN/Web/Controller/Search.pm +++ b/lib/MetaCPAN/Web/Controller/Search.pm @@ -30,6 +30,9 @@ sub index : Path : Args(0) { $query =~ s{\.pm\b}{}; } + $query =~ s/^\s+//; + $query =~ s/\s+$//; + my $model = $c->model('API::Module'); my $from = ( $req->page - 1 ) * $page_size; if ( diff --git a/t/controller/search/precision.t b/t/controller/search/precision.t index 77dffc81a4..62d04563a2 100644 --- a/t/controller/search/precision.t +++ b/t/controller/search/precision.t @@ -18,6 +18,14 @@ my %tests = ( 'dbix class resultset' => 'DBIx::Class::ResultSet', ); +my %authors = ( + ' LLAP ' => 'LLAP', + 'PERLER ' => 'PERLER', + ' NEILB' => 'NEILB', + 'RWSTAUNER' => 'RWSTAUNER', + ' OALDERS ' => 'OALDERS', +); + test_psgi app, sub { my $cb = shift; for my $k ( sort keys %tests ) { @@ -29,6 +37,17 @@ test_psgi app, sub { '//div[@class="module-result"][1]/big[1]//a[1]'); is( $module, $v, "$v is first result" ); } + + for my $k ( sort keys %authors ) { + ok( my $res = $cb->( GET "/search?q=$k" ), qq{search for "$k"} ); + my $v = $authors{$k}; + my $tx = tx($res); + my $author + = $tx->find_value( + '//div[@class="author-results"]/ul[@class="authors clearfix"]/li[1]/a[1]' + ); + like( $author, qr/\b$v\b/, "$v is first result" ); + } }; done_testing;