diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2016-02-21 11:38:00 -0800 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2016-02-21 12:02:29 -0800 |
commit | b45641c374a4e34a351ecee61334be0c5c9c4341 (patch) | |
tree | 4ca973ab29a276e366fe9e02ae620a36c1382f61 /src/pcresearch.c | |
parent | 36e0587a3cdeea24365168f96187b937739f2bd3 (diff) | |
download | grep-b45641c374a4e34a351ecee61334be0c5c9c4341.tar.gz |
grep: -Pz is incompatible with ^ and $
Problem reported by Sergei Trofimovich in: http://bugs.gnu.org/22655
* NEWS: Document this.
* src/pcresearch.c (Pcompile): Warn with -Pz and anchors.
* tests/pcre: Test new behavior.
Diffstat (limited to 'src/pcresearch.c')
-rw-r--r-- | src/pcresearch.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/pcresearch.c b/src/pcresearch.c index 3fee67a3..3b8e7953 100644 --- a/src/pcresearch.c +++ b/src/pcresearch.c @@ -124,6 +124,20 @@ Pcompile (char const *pattern, size_t size) /* FIXME: Remove these restrictions. */ if (memchr (pattern, '\n', size)) error (EXIT_TROUBLE, 0, _("the -P option only supports a single pattern")); + if (! eolbyte) + { + bool escaped = false; + for (p = pattern; *p; p++) + if (escaped) + escaped = false; + else + { + escaped = *p == '\\'; + if (*p == '^' || *p == '$') + error (EXIT_TROUBLE, 0, + _("unescaped ^ or $ not supported with -Pz")); + } + } *n = '\0'; if (match_words) |