mirror of
https://https.git.savannah.gnu.org/git/grep.git
synced 2026-01-26 15:39:06 +00:00
grep: avoid regression with -mN and any of -q, -l, -L
* src/grep.c (grepbuf): Handle this case: echo x|grep -l -m1 . making it print only the file name, and not the matched line. (main): Set out_quiet also when exit_on_match (-q) is set, so "echo x|grep -q -m1 ." no longer prints the matched line. * tests/max-count-overread: Add those tests, from https://bugs.gnu.org/68989#21
This commit is contained in:
parent
a4628e58dd
commit
52418599b3
@ -1487,6 +1487,8 @@ grepbuf (char *beg, char const *lim)
|
||||
break;
|
||||
if (!out_invert || p < b)
|
||||
{
|
||||
if (list_files != LISTFILES_NONE)
|
||||
return 1;
|
||||
char *prbeg = out_invert ? p : b;
|
||||
char *prend = out_invert ? b : endp;
|
||||
prtext (prbeg, prend);
|
||||
@ -2899,7 +2901,7 @@ main (int argc, char **argv)
|
||||
if (max_count == INTMAX_MAX)
|
||||
done_on_match = true;
|
||||
}
|
||||
out_quiet = count_matches | done_on_match;
|
||||
out_quiet = count_matches | done_on_match | exit_on_match;
|
||||
|
||||
if (out_after < 0)
|
||||
out_after = default_context;
|
||||
|
||||
@ -18,4 +18,14 @@ printf 'x\nx\nx\n' >in || framework_failure
|
||||
(grep -m2 x >/dev/null && head -n1) <in >out || fail=1
|
||||
compare exp out || fail=1
|
||||
|
||||
# The following two tests would fail before v3.11-70
|
||||
echo x > in || framework_failure_
|
||||
echo in > exp || framework_failure_
|
||||
grep -l -m1 . in > out || fail=1
|
||||
compare exp out || fail=1
|
||||
|
||||
# Ensure that this prints nothing and exits successfully.
|
||||
grep -q -m1 . in > out || fail=1
|
||||
compare /dev/null out || fail=1
|
||||
|
||||
Exit $fail
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user