Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Trim leading and trailing whitespace from search query
Fixes #1621.
  • Loading branch information
zakame authored and haarg committed Jun 30, 2017
1 parent 1da2e25 commit 9c864d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/MetaCPAN/Web/Controller/Search.pm
Expand Up @@ -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 (
Expand Down
19 changes: 19 additions & 0 deletions t/controller/search/precision.t
Expand Up @@ -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 ) {
Expand All @@ -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;

0 comments on commit 9c864d7

Please sign in to comment.