summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2014-06-27 12:31:29 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2014-06-27 12:32:02 -0700
commit639bfd84e719c451d810015d51386f6a0cc47a0d (patch)
tree21de216d07c13b4d2057a2a82c1d31e2ad402098
parenta5ef4c423bc583333cb465b72eff7b0dca7f68db (diff)
downloadgrep-639bfd84e719c451d810015d51386f6a0cc47a0d.tar.gz
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.
-rw-r--r--NEWS4
-rw-r--r--doc/grep.texi1
-rw-r--r--src/grep.c4
-rw-r--r--tests/ere.tests3
-rw-r--r--tests/spencer1.tests2
5 files changed, 12 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index 1af3def5..550bf4c1 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 c9417e51..10cc2e44 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 7c0f8a86..f2fca744 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 e0aad2a8..8ab6510e 100644
--- a/tests/ere.tests
+++ b/tests/ere.tests
@@ -215,3 +215,6 @@
0@CC[13]1|a{21}[23][EO][123][Es][12]a{15}aa[34][EW]aaaaaaa[X]a@CC11
0@a?b@ab
2@b{1000000000}@ESIZE
+0@)@)
+1@)@x
+0@\()\((a\())(b))@()(a()b)
diff --git a/tests/spencer1.tests b/tests/spencer1.tests
index 36c0b9ec..50581e86 100644
--- a/tests/spencer1.tests
+++ b/tests/spencer1.tests
@@ -59,7 +59,7 @@
0@a\(*b@ab
0@a\(*b@a((b
1@a\x@a\x
-2@abc)@-
+1@abc)@-
2@(abc@-
0@((a))@abc
0@(a)b(c)@abc