diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2020-09-18 14:49:51 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2020-09-18 14:51:53 -0700 |
commit | 220bd3882cb32b8830dcc742e46aaa93a8c8f9e5 (patch) | |
tree | 300499790d2589710c951d759b6e3454d30de7c1 | |
parent | b6d95a4e6b57cd260040fb83f828e81b01acd720 (diff) | |
download | grep-220bd3882cb32b8830dcc742e46aaa93a8c8f9e5.tar.gz |
grep: "grep '\)'" reports an error again
* src/grep.c (try_fgrep_pattern): With -G, pass \) through to
GEAcompile so that it can complain. This fixes an unexpected
change in behavior from grep 3.4 and earlier.
* tests/filename-lineno.pl: Add tests for this sort of thing.
-rw-r--r-- | src/grep.c | 6 | ||||
-rwxr-xr-x | tests/filename-lineno.pl | 16 |
2 files changed, 22 insertions, 0 deletions
@@ -2419,6 +2419,8 @@ try_fgrep_pattern (int matcher, char *keys, size_t *len_p) goto fail; case '(': case '+': case '?': case '{': case '|': + /* There is no "case ')'" here, as "grep -E ')'" acts like + "grep -E '\)'". */ if (matcher != G_MATCHER_INDEX) goto fail; break; @@ -2435,6 +2437,10 @@ try_fgrep_pattern (int matcher, char *keys, size_t *len_p) goto fail; case '(': case '+': case '?': case '{': case '|': + /* Pass '\)' to GEAcompile so it can complain. Otherwise, + "grep '\)'" would act like "grep ')'" while "grep '.*\)' + would be an error. */ + case ')': if (matcher == G_MATCHER_INDEX) goto fail; FALLTHROUGH; diff --git a/tests/filename-lineno.pl b/tests/filename-lineno.pl index 8940b1c7..ebd8d1ec 100755 --- a/tests/filename-lineno.pl +++ b/tests/filename-lineno.pl @@ -87,6 +87,22 @@ my @Tests = $err_subst, {ERR => "$prog: Unmatched [...\n" x 2}, ], + + # Test unmatched ) as well. It is OK with -E and an error with -G and -P. + ['invalid-re-E-paren', '-E ")"', {IN=>''}, {EXIT=>1}], + ['invalid-re-E-star-paren', '-E ".*)"', {IN=>''}, {EXIT=>1}], + ['invalid-re-G-paren', '-G "\\)"', {EXIT=>2}, + {ERR => "$prog: Unmatched ) or \\)\n"}, + ], + ['invalid-re-G-star-paren', '-G "a.*\\)"', {EXIT=>2}, + {ERR => "$prog: Unmatched ) or \\)\n"}, + ], + ['invalid-re-P-paren', '-P ")"', {EXIT=>2}, + {ERR => "$prog: unmatched parentheses\n"}, + ], + ['invalid-re-P-star-paren', '-P "a.*)"', {EXIT=>2}, + {ERR => "$prog: unmatched parentheses\n"}, + ], ); my $save_temps = $ENV{DEBUG}; |