summaryrefslogtreecommitdiff
path: root/gitweb
diff options
context:
space:
mode:
authorLibravatar Jakub Narebski <jnareb@gmail.com>2012-01-05 21:32:56 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2012-01-05 13:29:51 -0800
commit8e09fd1a1e5ea8eaec960d47be51bde85df8870e (patch)
tree126a0cdb8c40bc78fd2c36f26bf4808e9154bb81 /gitweb
parentgitweb: Fix file links in "grep" search (diff)
downloadtgif-8e09fd1a1e5ea8eaec960d47be51bde85df8870e.tar.xz
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 <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'gitweb')
-rwxr-xr-xgitweb/gitweb.perl5
1 files changed, 3 insertions, 2 deletions
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 1d2f046736..08020b0776 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -5699,7 +5699,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");
@@ -5721,7 +5721,8 @@ sub git_search_files {
$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 "</td></tr>\n";