Skip to content

Commit

Permalink
make utf8::upgrade() of a REGEXP a NOOP
Browse files Browse the repository at this point in the history
RT #131821

After my recent commit

    v5.27.2-30-gdf6b4bd, "give REGEXP SVs the POK flag again",

    $r = qr/.../; utf8::upgrade($$r);

was setting the utf8 flag on the compiled REGEXP SV, which made no sense,
as the regex was already compiled and individual nodes would remain
non-utf8.

The POK flag was removed from REGEXPs in 5.18.0, but before then it didn't
seem to matter if the utf8 flag got set later, but it does now - it broke
a Tk test.
  • Loading branch information
iabyn committed Aug 4, 2017
1 parent 97f6857 commit fde84d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 6 additions & 1 deletion sv.c
Original file line number Diff line number Diff line change
Expand Up @@ -3462,7 +3462,12 @@ Perl_sv_utf8_upgrade_flags_grow(pTHX_ SV *const sv, const I32 flags, STRLEN extr
}
}

if (SvUTF8(sv)) {
/* SVt_REGEXP's shouldn't be upgraded to UTF8 - they're already
* compiled and individual nodes will remain non-utf8 even if the
* stringified version of the pattern gets upgraded. Whether the
* PVX of a REGEXP should be grown or we should just croak, I don't
* know - DAPM */
if (SvUTF8(sv) || isREGEXP(sv)) {
if (extra) SvGROW(sv, SvCUR(sv) + extra);
return SvCUR(sv);
}
Expand Down
11 changes: 10 additions & 1 deletion t/op/qr.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ BEGIN {
require './test.pl';
}

plan(tests => 32);
plan(tests => 33);

sub r {
return qr/Good/;
Expand Down Expand Up @@ -110,3 +110,12 @@ sub {
is $_[0], "$str ", 'stringifying regexpvlv in place';
}
->((\my%hash)->{key});

# utf8::upgrade on an SVt_REGEXP should be a NOOP.
# RT #131821

{
my $r1 = qr/X/i;
utf8::upgrade($$r1);
like "xxx", $r1, "RT #131821 utf8::upgrade: case insensitive";
}

0 comments on commit fde84d2

Please sign in to comment.