git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] grep: fix word-regexp at the beginning of lines
@ 2009-05-23 11:45 René Scharfe
  0 siblings, 0 replies; only message in thread
From: René Scharfe @ 2009-05-23 11:45 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git Mailing List

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>
---
Embarrassing.

 grep.c          |    1 +
 t/t7002-grep.sh |    9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/grep.c b/grep.c
index a649f06..cc6d5b0 100644
--- a/grep.c
+++ b/grep.c
@@ -360,6 +360,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
 			bol = pmatch[0].rm_so + bol + 1;
 			while (word_char(bol[-1]) && bol < eol)
 				bol++;
+			eflags |= REG_NOTBOL;
 			if (bol < eol)
 				goto again;
 		}
diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh
index b815937..f275af8 100755
--- a/t/t7002-grep.sh
+++ b/t/t7002-grep.sh
@@ -16,12 +16,13 @@ test_expect_success setup '
 		echo foo mmap bar_mmap
 		echo foo_mmap bar mmap baz
 	} >file &&
+	echo ww w >w &&
 	echo x x xx x >x &&
 	echo y yy >y &&
 	echo zzz > z &&
 	mkdir t &&
 	echo test >t/t &&
-	git add file x y z t/t &&
+	git add file w x y z t/t &&
 	test_tick &&
 	git commit -m initial
 '
@@ -48,6 +49,12 @@ do
 		diff expected actual
 	'
 
+	test_expect_success "grep -w $L (w)" '
+		: >expected &&
+		! git grep -n -w -e "^w" >actual &&
+		test_cmp expected actual
+	'
+
 	test_expect_success "grep -w $L (x)" '
 		{
 			echo ${HC}x:1:x x xx x
-- 
1.6.3.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2009-05-23 11:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-23 11:45 [PATCH] grep: fix word-regexp at the beginning of lines René Scharfe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).