From: Junio C Hamano Date: Tue, 17 Jan 2012 00:45:56 +0000 (-0800) Subject: Merge branch 'jn/maint-gitweb-grep-fix' X-Git-Tag: v1.7.9-rc2~7 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b63103e908af54e5e2eaa3faad350e4738ef0047;hp=6db5c6e43dccb380ca6e9947777985eb11248c31;p=git.git Merge branch 'jn/maint-gitweb-grep-fix' * jn/maint-gitweb-grep-fix: gitweb: Harden "grep" search against filenames with ':' gitweb: Fix file links in "grep" search --- diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 285fe8840..abb5a79af 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -5836,7 +5836,7 @@ sub git_search_files { my %co = @_; local $/ = "\n"; - open my $fd, "-|", git_cmd(), 'grep', '-n', + open my $fd, "-|", git_cmd(), 'grep', '-n', '-z', $search_use_regexp ? ('-E', '-i') : '-F', $searchtext, $co{'tree'} or die_error(500, "Open git-grep failed"); @@ -5852,13 +5852,14 @@ sub git_search_files { my $lastfile = ''; while (my $line = <$fd>) { chomp $line; - my ($file, $lno, $ltext, $binary); + my ($file, $file_href, $lno, $ltext, $binary); last if ($matches++ > 1000); if ($line =~ /^Binary file (.+) matches$/) { $file = $1; $binary = 1; } else { - (undef, $file, $lno, $ltext) = split(/:/, $line, 4); + ($file, $lno, $ltext) = split(/\0/, $line, 3); + $file =~ s/^$co{'tree'}://; } if ($file ne $lastfile) { $lastfile and print "\n"; @@ -5867,10 +5868,10 @@ sub git_search_files { } else { print "\n"; } + $file_href = href(action=>"blob", hash_base=>$co{'id'}, + file_name=>$file); print "". - $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'}, - file_name=>"$file"), - -class => "list"}, esc_path($file)); + $cgi->a({-href => $file_href, -class => "list"}, esc_path($file)); print "\n"; $lastfile = $file; } @@ -5888,10 +5889,9 @@ sub git_search_files { $ltext = esc_html($ltext, -nbsp=>1); } print "
" . - $cgi->a({-href => href(action=>"blob", hash=>$co{'hash'}, - file_name=>"$file").'#l'.$lno, - -class => "linenr"}, sprintf('%4i', $lno)) - . ' ' . $ltext . "
\n"; + $cgi->a({-href => $file_href.'#l'.$lno, + -class => "linenr"}, sprintf('%4i', $lno)) . + ' ' . $ltext . "\n"; } } if ($lastfile) {