@matheusbsbs / matheus-bagliano / commits / 7e431ef9ab
Fork 0

gitweb: Separate search regexp from search text

Separate search text, which is saved in $searchtext global variable, and is used in links, as default value for the textfield in search form, and for pickaxe search, from search regexp, which is saved in $search_regexp global variable, and is used as parameter to --grep, --committer or --author options to git-rev-list, and for searching commit body in gitweb. For now $search_regexp is unconditionallt equal to quotemeta($searchtext), meaning that we always search for fixed string. This fixes bug where 'next page' links for 'search' view didn't work for searchtext containing quotable characters, like `@'. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jakub Narebski committed May 16, 2007 at 01:56 UTC 7e431ef9ab933d7ff899a999e40627ab49774f3a
1 file changed +4 -3
gitweb/gitweb.perl
+4 -3
@@ -365,6 +365,7 @@ if (defined $page) {
365 }
366
367 our $searchtext = $cgi->param('s');
368 +our $search_regexp;
369 if (defined $searchtext) {
370 if ($searchtext =~ m/[^a-zA-Z0-9_\.\/\-\+\:\@ ]/) {
371 die_error(undef, "Invalid search parameter");
@@ -372,7 +373,7 @@ if (defined $searchtext) {
373 if (length($searchtext) < 2) {
374 die_error(undef, "At least two characters are required for search parameter");
375 }
375 - $searchtext = quotemeta $searchtext;
376 + $search_regexp = quotemeta $searchtext;
377 }
378
379 our $searchtype = $cgi->param('st');
@@ -3244,7 +3245,7 @@ sub git_search_grep_body {
3245 esc_html(chop_str($co{'title'}, 50)) . "<br/>");
3246 my $comment = $co{'comment'};
3247 foreach my $line (@$comment) {
3247 - if ($line =~ m/^(.*)($searchtext)(.*)$/i) {
3248 + if ($line =~ m/^(.*)($search_regexp)(.*)$/i) {
3249 my $lead = esc_html($1) || "";
3250 $lead = chop_str($lead, 30, 10);
3251 my $match = esc_html($2) || "";
@@ -4626,7 +4627,7 @@ sub git_search {
4627 } elsif ($searchtype eq 'committer') {
4628 $greptype = "--committer=";
4629 }
4629 - $greptype .= $searchtext;
4630 + $greptype .= $search_regexp;
4631 my @commitlist = parse_commits($hash, 101, (100 * $page), $greptype);
4632
4633 my $paging_nav = '';