Skip to content

Commit dbb6a4a

Browse files
René Scharfegitster
authored andcommitted
grep: fix word-regexp at the beginning of lines
After bol is forwarded, it doesn't represent the beginning of the line any more. This means that the beginning-of-line marker (^) mustn't match, i.e. the regex flag REG_NOTBOL needs to be set. This bug was introduced by fb62eb7 ("grep -w: forward to next possible position after rejected match"). Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e701fad commit dbb6a4a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

grep.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
360360
bol = pmatch[0].rm_so + bol + 1;
361361
while (word_char(bol[-1]) && bol < eol)
362362
bol++;
363+
eflags |= REG_NOTBOL;
363364
if (bol < eol)
364365
goto again;
365366
}

t/t7002-grep.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ test_expect_success setup '
1616
echo foo mmap bar_mmap
1717
echo foo_mmap bar mmap baz
1818
} >file &&
19+
echo ww w >w &&
1920
echo x x xx x >x &&
2021
echo y yy >y &&
2122
echo zzz > z &&
2223
mkdir t &&
2324
echo test >t/t &&
24-
git add file x y z t/t &&
25+
git add file w x y z t/t &&
2526
test_tick &&
2627
git commit -m initial
2728
'
@@ -48,6 +49,12 @@ do
4849
diff expected actual
4950
'
5051

52+
test_expect_success "grep -w $L (w)" '
53+
: >expected &&
54+
! git grep -n -w -e "^w" >actual &&
55+
test_cmp expected actual
56+
'
57+
5158
test_expect_success "grep -w $L (x)" '
5259
{
5360
echo ${HC}x:1:x x xx x

0 commit comments

Comments
 (0)