From 9a9c6e39ba4c8f4f2cecb147c7e6464bec2d8b55 Mon Sep 17 00:00:00 2001 From: Ari Sundholm Date: Tue, 29 Jan 2019 14:42:57 +0100 Subject: grep: fix -x -v with certain pattern orders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We found out that busybox -x -v is a bit broken: ari@ari-thinkpad:~/busybox$ echo ' aa bb cc' | ./busybox grep -x -e 'aa.*' -e '.*bb.*' aa bb cc ari@ari-thinkpad:~/busybox$ echo ' aa bb cc' | ./busybox grep -x -v -e 'aa.*' -e '.*bb.*' ari@ari-thinkpad:~/busybox$ echo ' aa bb cc' | ./busybox grep -x -e '.*aa.*' -e 'bb.*' aa bb cc ari@ari-thinkpad:~/busybox$ echo ' aa bb cc' | ./busybox grep -x -v -e '.*aa.*' -e 'bb.*' aa bb cc Last one is wrong. This patch fixes the issue by making sure that the variable 'found' never makes a transition from 1 to 0, as this would mean that grep previously found a match on this input line. Signed-off-by: Ari Sundholm Signed-off-by: Niko Vähäsarja Signed-off-by: Denys Vlasenko --- testsuite/grep.tests | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'testsuite/grep.tests') diff --git a/testsuite/grep.tests b/testsuite/grep.tests index e57889790..26f8e69cf 100755 --- a/testsuite/grep.tests +++ b/testsuite/grep.tests @@ -177,6 +177,13 @@ testing "grep -w word match second word" \ "bword,word\n""wordb,word\n""bwordb,word\n" \ "" + +testing "grep -x -v -e EXP1 -e EXP2 finds nothing if either EXP matches" \ + "grep -x -v -e '.*aa.*' -e 'bb.*'; echo \$?" \ + "1\n" \ + "" \ + " aa bb cc\n" + # -r on symlink to dir should recurse into dir mkdir -p grep.testdir/foo echo bar > grep.testdir/foo/file -- cgit v1.2.3