]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
grep: fix null pattern and empty pattern file behavior
authorKyle Evans <kevans@FreeBSD.org>
Thu, 4 Feb 2021 21:26:45 +0000 (15:26 -0600)
committerKyle Evans <kevans@FreeBSD.org>
Thu, 11 Feb 2021 15:19:26 +0000 (09:19 -0600)
commit92ddb6090b0c5091a64855a514676a452c10750c
tree5d753ed591575fa6f6780d24fb128e4fd60e280c
parent07c84bb078e1974be265fc921481ee1608684103
grep: fix null pattern and empty pattern file behavior

The null pattern semantics were terrible because I tried to match gnugrep,
but I got it wrong.  Let's unwind that:

- The null pattern should match every line if neither -w nor -x.
- The null pattern should match empty lines if -x.
- The null pattern should not match any lines if -w.

The first two will stop processing (shortcut) even if additional patterns
are specified. In any other case, we will continue processing other
patterns.  If no other patterns are specified beside a null pattern, then
we match if neither -w nor -x or set and do not match if either of those
are specified.

The justification for -w is that it should match on a whole word, but the
null pattern deos not have a whole word to match on.

Empty pattern files should never match anything, and more importantly, -v
should cause everything to be written.

PR: 253209

(cherry picked from commit f823c6dc730b0dd08b54a53be1d8fd587eee7021)
contrib/netbsd-tests/usr.bin/grep/t_grep.sh
usr.bin/grep/grep.c
usr.bin/grep/util.c