@matheusbsbs / matheus-bagliano / commits / dbb6a4ada6
Fork 0

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 fb62eb7fab97cea880ea7fe4f341a4dfad14ab48 ("grep -w: forward to next possible position after rejected match"). Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed May 23, 2009 at 13:45 UTC dbb6a4ada6c6c1065b62313127ff032196e9d232
2 files changed +9 -1
grep.c
+1
@@ -360,6 +360,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
360 bol = pmatch[0].rm_so + bol + 1;
361 while (word_char(bol[-1]) && bol < eol)
362 bol++;
363 + eflags |= REG_NOTBOL;
364 if (bol < eol)
365 goto again;
366 }
t/t7002-grep.sh
+8 -1
@@ -16,12 +16,13 @@ test_expect_success setup '
16 echo foo mmap bar_mmap
17 echo foo_mmap bar mmap baz
18 } >file &&
19 + echo ww w >w &&
20 echo x x xx x >x &&
21 echo y yy >y &&
22 echo zzz > z &&
23 mkdir t &&
24 echo test >t/t &&
24 - git add file x y z t/t &&
25 + git add file w x y z t/t &&
26 test_tick &&
27 git commit -m initial
28 '
@@ -48,6 +49,12 @@ do
49 diff expected actual
50 '
51
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 +
58 test_expect_success "grep -w $L (x)" '
59 {
60 echo ${HC}x:1:x x xx x