This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #96230] Stop qr// from reusing last pattern
authorFather Chrysostomos <sprout@cpan.org>
Sat, 22 Sep 2012 14:13:36 +0000 (07:13 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 22 Sep 2012 17:06:18 +0000 (10:06 -0700)
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.

pp_hot.c
t/op/qr.t

index 4100ae2..827395f 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1286,8 +1286,10 @@ PP(pp_match)
 
 
 
-    /* empty pattern special-cased to use last successful pattern if possible */
-    if (!RX_PRELEN(rx) && PL_curpm) {
+    /* empty pattern special-cased to use last successful pattern if
+       possible, except for qr// */
+    if (!((struct regexp *)SvANY(rx))->mother_re && !RX_PRELEN(rx)
+     && PL_curpm) {
        pm = PL_curpm;
        rx = PM_GETRE(pm);
     }
index 83bb3d9..4130799 100644 (file)
--- a/t/op/qr.t
+++ b/t/op/qr.t
@@ -7,7 +7,7 @@ BEGIN {
     require './test.pl';
 }
 
-plan(tests => 18);
+plan(tests => 19);
 
 sub r {
     return qr/Good/;
@@ -59,3 +59,7 @@ $$e = 'Fake!';
 is($$e, 'Fake!');
 object_ok($e, 'Stew');
 like("$e", qr/\Stew=SCALAR\(0x[0-9a-f]+\)\z/);
+
+# [perl #96230] qr// should not have the reuse-last-pattern magic
+"foo" =~ /foo/;
+like "bar",qr//,'[perl #96230] =~ qr// does not reuse last successful pat';