Skip to content

Commit 75f0056

Browse files
committed
fix search/web quoting
1 parent 19ef3ef commit 75f0056

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/MetaCPAN/Model/Search.pm

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,15 @@ sub search_web {
7979
$page_size //= 20;
8080
$from //= 0;
8181

82-
$search_term
83-
=~ s{([ + - = > < ! & | ( ) { } \[ \] ^ " ~ * ? \ / ])}{\\$1}x;
82+
$search_term =~ s{([+=><!&|\(\)\{\}[\]\^"~*?\\/])}{\\$1}g;
8483

8584
# munge the search_term
8685
# these would be nicer if we had variable-length lookbehinds...
8786
# Allow q = 'author:LLAP' or 'module:Data::Page' or 'dist:'
88-
# We are mapping to correct ES fields here - wonder if ANYONE
89-
# uses these?!?!?!
87+
# We are mapping to correct ES fields here - relied on by metacpan-web
88+
# tests.
9089
#
9190
# The exceptions below are used specifically by the front end search.
92-
# We've temporarily removed the ":" from the regex above so that the the
93-
# author/dist/module searches work again. The were broken in 225749b6e.
9491
$search_term #
9592
=~ s{(^|\s)author:([a-zA-Z]+)(?=\s|$)}{$1author:\U$2\E}g;
9693
$search_term

t/model/search.t

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ ok( $search->_not_rogue, '_not_rogue' );
5959
is( @{ $results->{results} }, 5, '5 results on author search' );
6060
}
6161

62+
{
63+
my $results = $search->search_web('author:Mo BadPod');
64+
isnt( @{ $results->{results} },
65+
0, '>0 results on author search with extra' );
66+
}
67+
68+
{
69+
eval { $search->search_web('usr/bin/env') };
70+
is( $@, '', 'search term with a / no exception' );
71+
}
72+
6273
{
6374
my $long_form = $search->search_web('distribution:Pod-Pm');
6475
my $short_form = $search->search_web('dist:Pod-Pm');

0 commit comments

Comments
 (0)