From 626eba1b8a7ccd839fe96ee94800b059c5981461 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 27 Jun 2014 12:31:29 -0700 Subject: [PATCH] grep: with -E, unmatched ')' matches itself Problem reported by Nathan Weeks in: http://bugs.gnu.org/17856 * src/grep.c (Ecompile): Also specify RE_UNMATCHED_RIGHT_PAREN_ORD. * doc/grep.texi (Fundamental Structure), NEWS: Document this. * tests/ere.tests: Add a couple of tests for this. * tests/spencer1.tests: Fix exit status. --- NEWS | 4 ++++ doc/grep.texi | 1 + src/grep.c | 4 +++- tests/ere.tests | 3 +++ tests/spencer1.tests | 2 +- 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 1af3def..550bf4c 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,10 @@ GNU grep NEWS -*- outline -*- Performance has improved for very long strings in patterns. +** Bug fixes + + grep -E rejected unmatched ')', instead of treating it like '\)'. + [bug present since "the beginning"] * Noteworthy changes in release 2.20 (2014-06-03) [stable] diff --git a/doc/grep.texi b/doc/grep.texi index c9417e5..10cc2e4 100644 --- a/doc/grep.texi +++ b/doc/grep.texi @@ -1208,6 +1208,7 @@ Repetition takes precedence over concatenation, which in turn takes precedence over alternation. A whole expression may be enclosed in parentheses to override these precedence rules and form a subexpression. +An unmatched @samp{)} matches just itself. @node Character Classes and Bracket Expressions @section Character Classes and Bracket Expressions diff --git a/src/grep.c b/src/grep.c index 7c0f8a8..f2fca74 100644 --- a/src/grep.c +++ b/src/grep.c @@ -1638,7 +1638,9 @@ Gcompile (char const *pattern, size_t size) static void Ecompile (char const *pattern, size_t size) { - GEAcompile (pattern, size, RE_SYNTAX_POSIX_EGREP | RE_NO_EMPTY_RANGES); + GEAcompile (pattern, size, + (RE_SYNTAX_POSIX_EGREP | RE_NO_EMPTY_RANGES + | RE_UNMATCHED_RIGHT_PAREN_ORD)); } static void diff --git a/tests/ere.tests b/tests/ere.tests index e0aad2a..8ab6510 100644 --- a/tests/ere.tests +++ b/tests/ere.tests @@ -215,3 +215,6 @@ address@hidden|address@hidden address@hidden@ab address@hidden@ESIZE +0@)@) +1@)@x address@hidden()\((a\())(b))@()(a()b) diff --git a/tests/spencer1.tests b/tests/spencer1.tests index 36c0b9e..50581e8 100644 --- a/tests/spencer1.tests +++ b/tests/spencer1.tests @@ -59,7 +59,7 @@ address@hidden(address@hidden address@hidden(address@hidden((b address@hidden@a\x address@hidden)@- address@hidden)@- 2@(address@hidden 0@((a))@abc 0@(a)b(c)@abc -- 1.9.3