bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#22655: grep -Pz '^' now fails!


From: Zev Weiss
Subject: bug#22655: grep -Pz '^' now fails!
Date: Sat, 19 Nov 2016 03:22:07 -0600
User-agent: NeoMutt/20161014 (1.7.1)

On Sat, Nov 19, 2016 at 12:36:12AM -0800, Paul Eggert wrote:
Stephane Chazelas wrote:
one can
use (?m) if he wants ^ to match the beginning of each line in
the NUL-delimited record instead of just the beginning of the
record.

I think the intent is that ^ and $ should match only the line-terminator specified by -z (or by -z's absence). So the sort of usage you describe is unspecified and not supported. That being said, it does make sense to match tricky regular expressions like that line by line, even if this hurts performance. Otherwise, I suspect there are even trickier regular expressions that could reject a buffer full of lines even though it contains matching lines. When in doubt we should avoid optimization so I installed the attached patch into the master branch. Please give it a try.

From 0e00fe0fc34184b1cdcea92a671eb9ffebb4899b Mon Sep 17 00:00:00 2001
From: Paul Eggert <address@hidden>
Date: Sat, 19 Nov 2016 00:25:46 -0800
Subject: [PATCH] grep: -Pz no longer rejects ^, $

Problem reported by Stephane Chazelas (Bug#22655).
* NEWS: Document this.
* doc/grep.texi (grep Programs): Warn about -Pz.
* src/pcresearch.c (reflags): New static var.
(multibyte_locale): Remove static var; now local to Pcompile.
(Pcompile): Check for (? and (* too.  Set reflags instead of
dying when problematic operators are found.
(Pexecute): Use reflags to decide whether searches should
be multiline.
* tests/pcre: Test new behavior.

I'm a bit confused by this patch -- I see 'reflags' being tested in Pexecute(), but I don't see it getting set anywhere, just Pcompile()'s local 'flags'...I'm guessing 'flags' was supposed to be replaced by 'reflags'? (Not entirely certain though.)


Zev






reply via email to

[Prev in Thread] Current Thread [Next in Thread]