summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS5
-rw-r--r--doc/grep.texi13
-rw-r--r--src/grep.c13
-rwxr-xr-xtests/encoding-error4
4 files changed, 22 insertions, 13 deletions
diff --git a/NEWS b/NEWS
index 01be3509..a63a7b21 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,11 @@ GNU grep NEWS -*- outline -*-
* Noteworthy changes in release ?.? (????-??-??) [?]
+** Bug fixes
+
+ Grep no longer omits output merely because it follows an output line
+ suppressed due to encoding errors. [bug introduced in grep-2.21]
+
** Improvements
grep can be much faster now when standard output is /dev/null.
diff --git a/doc/grep.texi b/doc/grep.texi
index 7e51d45e..fcfad42e 100644
--- a/doc/grep.texi
+++ b/doc/grep.texi
@@ -610,18 +610,19 @@ Variables}), or null input bytes when the
@option{-z} (@option{--null-data}) option is not given (@pxref{Other
Options}).
-By default, @var{type} is @samp{binary}, and when @command{grep}
-discovers that a file is binary it suppresses any further output, and
-instead outputs either a one-line message saying that a binary file
-matches, or no message if there is no match.
+By default, @var{type} is @samp{binary}, and @command{grep}
+suppresses output afer null input binary data is discovered,
+and suppresses output lines that contain improperly encoded data.
+When some output is suppressed, @command{grep} follows any output
+with a one-line message saying that a binary file matches.
If @var{type} is @samp{without-match},
-when @command{grep} discovers that a file is binary
+when @command{grep} discovers null input binary data
it assumes that the rest of the file does not match;
this is equivalent to the @option{-I} option.
If @var{type} is @samp{text},
-@command{grep} processes a binary file as if it were text;
+@command{grep} processes binary data as if it were text;
this is equivalent to the @option{-a} option.
When @var{type} is @samp{binary}, @command{grep} may treat non-text
diff --git a/src/grep.c b/src/grep.c
index d07f5da2..65916ca0 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -1108,17 +1108,16 @@ print_offset (uintmax_t pos, int min_width, const char *color)
static bool
print_line_head (char *beg, size_t len, char const *lim, char sep)
{
- bool encoding_errors = false;
if (binary_files != TEXT_BINARY_FILES)
{
char ch = beg[len];
- encoding_errors = buf_has_encoding_errors (beg, len);
+ bool encoding_errors = buf_has_encoding_errors (beg, len);
beg[len] = ch;
- }
- if (encoding_errors)
- {
- encoding_error_output = done_on_match = out_quiet = true;
- return false;
+ if (encoding_errors)
+ {
+ encoding_error_output = true;
+ return false;
+ }
}
bool pending_sep = false;
diff --git a/tests/encoding-error b/tests/encoding-error
index 4b5fcb5b..0cbeffcc 100755
--- a/tests/encoding-error
+++ b/tests/encoding-error
@@ -35,6 +35,10 @@ grep '^X' in >out
test $? = 1 || fail=1
compare /dev/null out || fail=1
+grep . in >out || fail=1
+(cat a j && printf 'Binary file in matches\n') >exp || framework_failure_
+compare exp out || fail=1
+
grep -a . in >out || fail=1
compare in out