GNU bug report logs - #33062
grep matches too lazily when invoked with -zoP and matching backreference followed by newline

Previous Next

Package: grep;

Reported by: Johannes Riecken <johannes.riecken <at> gmail.com>

Date: Tue, 16 Oct 2018 14:42:02 UTC

Severity: normal

Tags: notabug

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 33062 in the body.
You can then email your comments to 33062 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#33062; Package coreutils. (Tue, 16 Oct 2018 14:42:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Johannes Riecken <johannes.riecken <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Tue, 16 Oct 2018 14:42:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Johannes Riecken <johannes.riecken <at> gmail.com>
To: bug-coreutils <at> gnu.org
Subject: grep matches too lazily when invoked with -zoP and matching
 backreference followed by newline
Date: Tue, 16 Oct 2018 14:55:34 +0200
[Message part 1 (text/plain, inline)]
Dear maintainers:

*Bug summary: *GNU grep 3.0-2 matches too lazily when invoked with -zoP and
matching backreference followed by newline

*Steps to reproduce:*

Create file cases:

foo
bar
  cases:
    1: foo
    2: bar
baz
  cases:
    3: baz
quux

And run grep -zoP '(\s*)cases:\n(\1.*\n)*' cases

*Expected output:*

  cases:
    1: foo
    2: bar
  cases:
    3: baz

* Actual output:*

  cases:

  cases:

Best regards,

Johannes Riecken
[Message part 2 (text/html, inline)]

Information forwarded to bug-coreutils <at> gnu.org:
bug#33062; Package coreutils. (Tue, 23 Oct 2018 23:18:02 GMT) Full text and rfc822 format available.

Message #8 received at 33062 <at> debbugs.gnu.org (full text, mbox):

From: Bernhard Voelker <mail <at> bernhard-voelker.de>
To: Johannes Riecken <johannes.riecken <at> gmail.com>, 33062 <at> debbugs.gnu.org
Subject: Re: bug#33062: grep matches too lazily when invoked with -zoP and
 matching backreference followed by newline
Date: Wed, 24 Oct 2018 01:16:57 +0200
reassign 33062 grep
stop

On 10/16/18 2:55 PM, Johannes Riecken wrote:
> Dear maintainers:
> 
> *Bug summary: *GNU grep 3.0-2 matches too lazily when invoked with -zoP and
> matching backreference followed by newline
> 
> *Steps to reproduce:*
> 
> Create file cases:
> 
> foo
> bar
>   cases:
>     1: foo
>     2: bar
> baz
>   cases:
>     3: baz
> quux
> 
> And run grep -zoP '(\s*)cases:\n(\1.*\n)*' cases
> 
> *Expected output:*
> 
>   cases:
>     1: foo
>     2: bar
>   cases:
>     3: baz
> 
> * Actual output:*
> 
>   cases:
> 
>   cases:
> 
> Best regards,
> 
> Johannes Riecken

Thanks for the report, however, you reached the GNU coreutils mailing list,
while your report is for 'grep'.

I'm therefore reassigning this issue to the GNU 'grep' package.

Have a nice day,
Berny





bug reassigned from package 'coreutils' to 'grep'. Request was from Bernhard Voelker <mail <at> bernhard-voelker.de> to control <at> debbugs.gnu.org. (Tue, 23 Oct 2018 23:18:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-grep <at> gnu.org:
bug#33062; Package grep. (Sun, 28 Oct 2018 10:32:02 GMT) Full text and rfc822 format available.

Message #13 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Bernhard Voelker <mail <at> bernhard-voelker.de>
To: Johannes Riecken <johannes.riecken <at> gmail.com>, 33062 <at> debbugs.gnu.org,
 bug-grep <at> gnu.org
Subject: Re: bug#33062: grep matches too lazily when invoked with -zoP and
 matching backreference followed by newline
Date: Sun, 28 Oct 2018 11:31:26 +0100
On 10/28/18 8:32 AM, Johannes Riecken wrote:
>> On Wed, Oct 24, 2018 at 1:17 AM Bernhard Voelker <mail <at> bernhard-voelker.de <mailto:mail <at> bernhard-voelker.de>> wrote:
>> reassign 33062 grep
>> stop
>>> On 10/16/18 2:55 PM, Johannes Riecken wrote:
>>> Dear maintainers:
>>>
>>> *Bug summary: *GNU grep 3.0-2 matches too lazily when invoked with -zoP and
>>> matching backreference followed by newline
>>>
>>> *Steps to reproduce:*
>>>
>>> Create file cases:
>>>
>>> foo
>>> bar
>>>   cases:
>>>     1: foo
>>>     2: bar
>>> baz
>>>   cases:
>>>     3: baz
>>> quux
>>>
>>> And run grep -zoP '(\s*)cases:\n(\1.*\n)*' cases
>>>
>>> *Expected output:*
>>>
>>>   cases:
>>>     1: foo
>>>     2: bar
>>>   cases:
>>>     3: baz
>>>
>>> * Actual output:*
>>>
>>>   cases:
>>>
>>>   cases:
>>>
>>> Best regards,
>>>
>>> Johannes Riecken
>>
>> Thanks for the report, however, you reached the GNU coreutils mailing list,
>> while your report is for 'grep'.
>>
>> I'm therefore reassigning this issue to the GNU 'grep' package.
>
> Thank you, could you please tell me where I can check the progress of my bug report after the reassignment? I didn't see
> it in the archives of the bug-grep mailing list.
> 
> Best wishes,
> Johannes

Well, it's still in the same GNU bug tracker:
  https://bugs.gnu.org/33062
but it seems that the bug wasn't forwarded automatically to the
bug-grep mailing list, thus adding that list explicitly ... hoping that
this doesn't open another bug.

Have a nice day,
Berny




Information forwarded to bug-grep <at> gnu.org:
bug#33062; Package grep. (Sun, 28 Oct 2018 10:32:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-grep <at> gnu.org:
bug#33062; Package grep. (Sun, 28 Oct 2018 12:20:02 GMT) Full text and rfc822 format available.

Message #19 received at 33062 <at> debbugs.gnu.org (full text, mbox):

From: Jim Meyering <jim <at> meyering.net>
To: johannes.riecken <at> gmail.com
Cc: 33062 <at> debbugs.gnu.org
Subject: Re: bug#33062: grep matches too lazily when invoked with -zoP and
 matching backreference followed by newline
Date: Sun, 28 Oct 2018 12:19:09 +0000
tags 33062 notabug
close 33062
stop

On Tue, Oct 16, 2018 at 2:42 PM Johannes Riecken
<johannes.riecken <at> gmail.com> wrote:
> *Bug summary: *GNU grep 3.0-2 matches too lazily when invoked with -zoP and
> matching backreference followed by newline
>
> *Steps to reproduce:*
>
> Create file cases:
>
> foo
> bar
>   cases:
>     1: foo
>     2: bar
> baz
>   cases:
>     3: baz
> quux
>
> And run grep -zoP '(\s*)cases:\n(\1.*\n)*' cases
>
> *Expected output:*
>
>   cases:
>     1: foo
>     2: bar
>   cases:
>     3: baz
>
> * Actual output:*
>
>   cases:
>
>   cases:

Thanks for the report.
However, this is not a bug.
The \s in your regexp matches the preceding newline, too, and that
forces the behavior you see.
I presume you wanted something like this:

$ printf '%s\n' foo bar '  cases:' '    1: foo' '    2: bar' baz '
cases:' '    3: baz' quux\
  | grep -zoP '( *)cases:\n(\1.*\n)*'
  cases:
    1: foo
    2: bar
  cases:
    3: baz

The adjusted regexp works because it accepts only spaces in the group.
Don't be tempted to allow TABs, but rather ensure the input is
expanded to use only spaces for indentation.




Added tag(s) notabug. Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Thu, 02 Jan 2020 01:12:01 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 33062 <at> debbugs.gnu.org and Johannes Riecken <johannes.riecken <at> gmail.com> Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Thu, 02 Jan 2020 01:12:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 30 Jan 2020 12:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 86 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.