develooper Front page | perl.perl5.porters | Postings from April 2015

[perl #124256] Regex loop for \K in lookbehind

Thread Previous
From:
James E Keenan via RT
Date:
April 28, 2015 00:54
Subject:
[perl #124256] Regex loop for \K in lookbehind
Message ID:
rt-4.0.18-4091-1430182442-1876.124256-15-0@perl.org
On Tue Apr 07 09:46:45 2015, ph10@hermes.cam.ac.uk wrote:
> This is a bug report for perl from ph10@hermes.cam.ac.uk,
> generated with the help of perlbug 1.40 running under perl 5.20.2.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> The command
> 
> perl -e 'while("aaaa" =~ /(?<=\Ka)/g){};'
> 
> puts Perl into an infinite loop. Without the \K in the assertion, it 
> finishes instantly. 

A little diagnostic:

#####
$ cat 124256-regex.pl 
# perl
use strict;
use warnings;
use 5.10.1;

while ("aaaa" =~ /(?<=a)/g) {
    say "Yes: <", join('|' => $`, $&, $'), ">";
}

say '';

# Below: Infinite loop
while ("aaaa" =~ /(?<=\Ka)/g) {
    say "Yes: <", join('|' => $`, $&, $'), ">";
}
#####

The top part produces:

#####
Yes: <a||aaa>
Yes: <aa||aa>
Yes: <aaa||a>
Yes: <aaaa||>
#####

The bottom part loops forever, producing:

#####
Yes: <|a|aaa>
#####

> I think this is a similar bug to the one I have just
> fixed in PCRE.
> 

Can you provide a link to that fix?

Thank you very much.

-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=124256

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About