{"thread":{"id":"19448","subject":"[PATCH] grep: fix word-regexp at the beginning of lines","startedAt":"2009-05-23T11:45:26Z","lastAt":"2009-05-23T11:45:26Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"114511","messageId":"4A17E1D6.10401@lsrfire.ath.cx","threadId":"19448","inReplyTo":null,"subject":"[PATCH] grep: fix word-regexp at the beginning of lines","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2009-05-23T11:45:26Z","receivedAt":"2009-05-23T11:45:26Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"After bol is forwarded, it doesn't represent the beginning of the line\nany more.  This means that the beginning-of-line marker (^) mustn't match,\ni.e. the regex flag REG_NOTBOL needs to be set.\n\nThis bug was introduced by fb62eb7fab97cea880ea7fe4f341a4dfad14ab48\n(\"grep -w: forward to next possible position after rejected match\").\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\nEmbarrassing.\n\n grep.c          |    1 +\n t/t7002-grep.sh |    9 ++++++++-\n 2 files changed, 9 insertions(+), 1 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex a649f06..cc6d5b0 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -360,6 +360,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,\n \t\t\tbol = pmatch[0].rm_so + bol + 1;\n \t\t\twhile (word_char(bol[-1]) && bol < eol)\n \t\t\t\tbol++;\n+\t\t\teflags |= REG_NOTBOL;\n \t\t\tif (bol < eol)\n \t\t\t\tgoto again;\n \t\t}\ndiff --git a/t/t7002-grep.sh b/t/t7002-grep.sh\nindex b815937..f275af8 100755\n--- a/t/t7002-grep.sh\n+++ b/t/t7002-grep.sh\n@@ -16,12 +16,13 @@ test_expect_success setup '\n \t\techo foo mmap bar_mmap\n \t\techo foo_mmap bar mmap baz\n \t} >file &&\n+\techo ww w >w &&\n \techo x x xx x >x &&\n \techo y yy >y &&\n \techo zzz > z &&\n \tmkdir t &&\n \techo test >t/t &&\n-\tgit add file x y z t/t &&\n+\tgit add file w x y z t/t &&\n \ttest_tick &&\n \tgit commit -m initial\n '\n@@ -48,6 +49,12 @@ do\n \t\tdiff expected actual\n \t'\n \n+\ttest_expect_success \"grep -w $L (w)\" '\n+\t\t: >expected &&\n+\t\t! git grep -n -w -e \"^w\" >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n \ttest_expect_success \"grep -w $L (x)\" '\n \t\t{\n \t\t\techo ${HC}x:1:x x xx x\n-- \n1.6.3.1\n"}]}