[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
grep branch, master, updated. v3.4-almost-30-g203ad5b
From: |
Jim Meyering |
Subject: |
grep branch, master, updated. v3.4-almost-30-g203ad5b |
Date: |
Fri, 18 Sep 2020 15:47:33 -0400 (EDT) |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grep".
The branch, master has been updated
via 203ad5b718ce349efa6bfa847b356d47dc5c584e (commit)
from 97cc60acf8d4ca48bf310a8bb123d0f8cefc1b99 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/grep.git/commit/?id=203ad5b718ce349efa6bfa847b356d47dc5c584e
commit 203ad5b718ce349efa6bfa847b356d47dc5c584e
Author: Jim Meyering <meyering@fb.com>
Date: Fri Sep 18 12:37:17 2020 -0700
grep: make echo .|grep '\.' match once again
The same applied for many other backslash-escaped bytes, not just
metacharacters. The switch to rawmemchr in v3.4-almost-10-g9393b97
made some parts of the code require the usually-guaranteed newline
sentinel at the end of each pattern. Before, some consumers used a
(correct) pattern length and did not care that try_fgrep_pattern could
transform a pattern (with sentinel) like "\\.\n" to "..\n", thus
violating that assumption.
* src/grep.c (try_fgrep_pattern): Preserve the invariant
that each regexp is newline-terminated.
* tests/backslash-dot: New file. Test for this.
* tests/Makefile.am (TESTS): Add it.
diff --git a/src/grep.c b/src/grep.c
index ba6b15d..497780e 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -2471,6 +2471,9 @@ try_fgrep_pattern (int matcher, char *keys, size_t *len_p)
{
*len_p = p - new_keys;
memcpy (keys, new_keys, p - new_keys);
+ /* We have just shortened this pattern.
+ Preserve the invariant that it is newline-terminated. */
+ keys[*len_p] = '\n';
}
result = F_MATCHER_INDEX;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 3ee2915..b29f26a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -66,6 +66,7 @@ TESTS = \
backref-alt \
backref-multibyte-slow \
backref-word \
+ backslash-dot \
backslash-s-and-repetition-operators \
backslash-s-vs-invalid-multibyte \
big-hole \
diff --git a/tests/backslash-dot b/tests/backslash-dot
new file mode 100755
index 0000000..3fddda5
--- /dev/null
+++ b/tests/backslash-dot
@@ -0,0 +1,20 @@
+#! /bin/sh
+# This once failed to match: echo . | grep '\.'
+#
+# Copyright (C) 2020 Free Software Foundation, Inc.
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+fail=0
+
+echo . > in || framework_failure_
+
+grep '\.' in > out 2> err || fail=1
+compare in out || fail=1
+compare /dev/null err || fail=1
+
+Exit $fail
-----------------------------------------------------------------------
Summary of changes:
src/grep.c | 3 +++
tests/Makefile.am | 1 +
tests/{binary-file-matches => backslash-dot} | 11 +++++------
3 files changed, 9 insertions(+), 6 deletions(-)
copy tests/{binary-file-matches => backslash-dot} (56%)
hooks/post-receive
--
grep
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- grep branch, master, updated. v3.4-almost-30-g203ad5b,
Jim Meyering <=