Skip to content

Commit 8e09fd1

Browse files
jnarebgitster
authored andcommitted
gitweb: Harden "grep" search against filenames with ':'
Run "git grep" in "grep" search with '-z' option, to be able to parse response also for files with filename containing ':' character. The ':' character is otherwise (without '-z') used to separate filename from line number and from matched line. Note that this does not protect files with filename containing embedded newline. This would be hard but doable for text files, and harder or even currently impossible with binary files: git does not quote filename in "Binary file <foo> matches" message, but new `--break` and/or `--header` options to git-grep could help here. Signed-off-by: Jakub Narebski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ff7f218 commit 8e09fd1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

gitweb/gitweb.perl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5699,7 +5699,7 @@ sub git_search_files {
56995699
my %co = @_;
57005700

57015701
local $/ = "\n";
5702-
open my $fd, "-|", git_cmd(), 'grep', '-n',
5702+
open my $fd, "-|", git_cmd(), 'grep', '-n', '-z',
57035703
$search_use_regexp ? ('-E', '-i') : '-F',
57045704
$searchtext, $co{'tree'}
57055705
or die_error(500, "Open git-grep failed");
@@ -5721,7 +5721,8 @@ sub git_search_files {
57215721
$file = $1;
57225722
$binary = 1;
57235723
} else {
5724-
(undef, $file, $lno, $ltext) = split(/:/, $line, 4);
5724+
($file, $lno, $ltext) = split(/\0/, $line, 3);
5725+
$file =~ s/^$co{'tree'}://;
57255726
}
57265727
if ($file ne $lastfile) {
57275728
$lastfile and print "</td></tr>\n";

0 commit comments

Comments
 (0)