develooper Front page | perl.perl5.porters | Postings from January 2019

[perl #133756] //g flag on regex with UTF-8 source causes regexoptimiser to wrongly reject a match

Thread Next
From:
Tony Cook via RT
Date:
January 10, 2019 00:27
Subject:
[perl #133756] //g flag on regex with UTF-8 source causes regexoptimiser to wrongly reject a match
Message ID:
rt-4.0.24-15712-1547080055-1440.133756-15-0@perl.org
You're going to facepalm yourself.

On Wed, 09 Jan 2019 06:11:06 -0800, nicholas wrote:
> For the case where the eval'd source code contains Ā in a code comment
> this
> doesn't match. Where the code comment is ÿ it does:
> 
> nicholas@dromedary-001 perl6$ cat /tmp/rule.pl
> use strict;
> use warnings;
> 
> my $mr = "L\xFCften Kalt";
> my $text = "L\xFCften Kalt";
> 
> # Culprit here is the //g flag:
> for my $char ("\xFF", "\x100", "\xFF", "\x100") {

Add:

  pos($text) = 0;

here and they all pass.

>     my $got = eval "\$text =~ /$mr/g; # $char";
> 
> if ($got) {
>     print "Y\n";
> } elsif ($@) {
>     print "\$\@: $@\n";
> } else {
>     print "n\n";
> }
> }

Tony

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

Thread Next


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