From: Hugo van der Sanden Date: Thu, 2 Jan 2003 14:33:49 +0000 (+0000) Subject: Re: [perl #17757] s///g fails when using English & study in 5.8.0 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4addbd3b37ffede9a798950435a751b9834e67d0;p=p5sagit%2Fp5-mst-13.2.git Re: [perl #17757] s///g fails when using English & study in 5.8.0 Message-Id: <200301021433.h02EXno03562@crypt.compulink.co.uk> p4raw-id: //depot/perl@18533 --- diff --git a/regexec.c b/regexec.c index f91af17..a6fd6ae 100644 --- a/regexec.c +++ b/regexec.c @@ -541,6 +541,9 @@ Perl_re_intuit_start(pTHX_ regexp *prog, SV *sv, char *strpos, start_shift + (s - strbeg), end_shift, pp, 0); else goto fail_finish; + /* we may be pointing at the wrong string */ + if (s && RX_MATCH_COPIED(prog)) + s = prog->subbeg + (s - SvPVX(sv)); if (data) *data->scream_olds = s; } @@ -1858,6 +1861,9 @@ Perl_regexec_flags(pTHX_ register regexp *prog, char *stringarg, register char * : (s = fbm_instr((unsigned char*)HOP3(s, back_min, strend), (unsigned char*)strend, must, PL_multiline ? FBMrf_MULTILINE : 0))) ) { + /* we may be pointing at the wrong string */ + if ((flags & REXEC_SCREAM) && RX_MATCH_COPIED(prog)) + s = prog->subbeg + (s - SvPVX(sv)); DEBUG_r( did_match = 1 ); if (HOPc(s, -back_max) > last1) { last1 = HOPc(s, -back_min); @@ -1944,6 +1950,9 @@ Perl_regexec_flags(pTHX_ register regexp *prog, char *stringarg, register char * end_shift, &scream_pos, 1); /* last one */ if (!last) last = scream_olds; /* Only one occurrence. */ + /* we may be pointing at the wrong string */ + else if (RX_MATCH_COPIED(prog)) + s = prog->subbeg + (s - SvPVX(sv)); } else { STRLEN len; diff --git a/t/op/subst.t b/t/op/subst.t index 797f241..59c3d21 100755 --- a/t/op/subst.t +++ b/t/op/subst.t @@ -7,7 +7,7 @@ BEGIN { } require './test.pl'; -plan( tests => 125 ); +plan( tests => 126 ); $x = 'foo'; $_ = "x"; @@ -508,5 +508,11 @@ is("<$_> <$s>", "<> <4>", "[perl #7806]"); is($_, "\n", "[perl #19048]"); } - - +# [perl #17757] interaction between saw_ampersand and study +{ + my $f = eval q{ $& }; + $f = "xx"; + study $f; + $f =~ s/x/y/g; + is($f, "yy", "[perl #17757]"); +}