Skip to content

Commit 7e31363

Browse files
author
Father Chrysostomos
committed
[perl #96230] Stop qr// from reusing last pattern
qr// should not be using the last-successful pattern, because it is "(?^:)", not the empty pattern. A stringified qr// does not use the last-successful pattern.
1 parent ab1d075 commit 7e31363

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pp_hot.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,8 +1286,10 @@ PP(pp_match)
12861286

12871287

12881288

1289-
/* empty pattern special-cased to use last successful pattern if possible */
1290-
if (!RX_PRELEN(rx) && PL_curpm) {
1289+
/* empty pattern special-cased to use last successful pattern if
1290+
possible, except for qr// */
1291+
if (!((struct regexp *)SvANY(rx))->mother_re && !RX_PRELEN(rx)
1292+
&& PL_curpm) {
12911293
pm = PL_curpm;
12921294
rx = PM_GETRE(pm);
12931295
}

t/op/qr.t

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ BEGIN {
77
require './test.pl';
88
}
99

10-
plan(tests => 18);
10+
plan(tests => 19);
1111

1212
sub r {
1313
return qr/Good/;
@@ -59,3 +59,7 @@ $$e = 'Fake!';
5959
is($$e, 'Fake!');
6060
object_ok($e, 'Stew');
6161
like("$e", qr/\Stew=SCALAR\(0x[0-9a-f]+\)\z/);
62+
63+
# [perl #96230] qr// should not have the reuse-last-pattern magic
64+
"foo" =~ /foo/;
65+
like "bar",qr//,'[perl #96230] =~ qr// does not reuse last successful pat';

0 commit comments

Comments
 (0)