diff options
author | Jim Meyering <meyering@fb.com> | 2020-09-18 12:37:17 -0700 |
---|---|---|
committer | Jim Meyering <meyering@fb.com> | 2020-09-18 12:45:17 -0700 |
commit | 203ad5b718ce349efa6bfa847b356d47dc5c584e (patch) | |
tree | 8d1d70e806b9196dc44cce977fd348267ac71c9c /tests | |
parent | 97cc60acf8d4ca48bf310a8bb123d0f8cefc1b99 (diff) | |
download | grep-203ad5b718ce349efa6bfa847b356d47dc5c584e.tar.gz |
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.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rwxr-xr-x | tests/backslash-dot | 20 |
2 files changed, 21 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 3ee29154..b29f26a6 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 00000000..3fddda58 --- /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 |