mirror of
https://github.com/git/git.git
synced 2024-11-24 02:17:02 +08:00
grep: continue case insensitive fixed string search after NUL chars
Functions for C strings, like strcasestr(), can't see beyond NUL characters. Check if there is such an obstacle on the line and try again behind it. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
1baddf4b37
commit
52d799a79f
12
grep.c
12
grep.c
@ -334,9 +334,15 @@ static int fixmatch(const char *pattern, char *line, char *eol,
|
||||
{
|
||||
char *hit;
|
||||
|
||||
if (ignore_case)
|
||||
hit = strcasestr(line, pattern);
|
||||
else
|
||||
if (ignore_case) {
|
||||
char *s = line;
|
||||
do {
|
||||
hit = strcasestr(s, pattern);
|
||||
if (hit)
|
||||
break;
|
||||
s += strlen(s) + 1;
|
||||
} while (s < eol);
|
||||
} else
|
||||
hit = memmem(line, eol - line, pattern, strlen(pattern));
|
||||
|
||||
if (!hit) {
|
||||
|
@ -55,4 +55,8 @@ test_expect_success 'git grep -F ile a' '
|
||||
git grep -F ile a
|
||||
'
|
||||
|
||||
test_expect_success 'git grep -Fi iLE a' '
|
||||
git grep -Fi iLE a
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Loading…
Reference in New Issue
Block a user