Fix for bug id 19990615.008, pos() unset during s///ge.
authorJarkko Hietaniemi <jhi@iki.fi>
Sun, 5 Nov 2000 19:38:24 +0000 (19:38 +0000)
committerJarkko Hietaniemi <jhi@iki.fi>
Sun, 5 Nov 2000 19:38:24 +0000 (19:38 +0000)
p4raw-id: //depot/perl@7562

pp_ctl.c
t/op/pos.t

index 729a438..fce163f 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -211,6 +211,21 @@ PP(pp_substcont)
     cx->sb_m = m = rx->startp[0] + orig;
     sv_catpvn(dstr, s, m-s);
     cx->sb_s = rx->endp[0] + orig;
+    { /* Update the pos() information. */
+       SV *sv = cx->sb_targ;
+       MAGIC *mg;
+       I32 i;
+       if (SvTYPE(sv) < SVt_PVMG)
+           SvUPGRADE(sv, SVt_PVMG);
+       if (!(mg = mg_find(sv, 'g'))) {
+           sv_magic(sv, Nullsv, 'g', Nullch, 0);
+           mg = mg_find(sv, 'g');
+       }
+       i = m - orig;
+       if (DO_UTF8(sv))
+           sv_pos_b2u(sv, &i);
+       mg->mg_len = i;
+    }
     cx->sb_rxtainted |= RX_MATCH_TAINTED(rx);
     rxres_save(&cx->sb_rxres, rx);
     RETURNOP(pm->op_pmreplstart);
index 46811b7..f3bc23c 100755 (executable)
@@ -1,6 +1,6 @@
 #!./perl
 
-print "1..3\n";
+print "1..4\n";
 
 $x='banana';
 $x=~/.a/g;
@@ -14,3 +14,10 @@ sub f { my $p=$_[0]; return $p }
 $x=~/.a/g;
 if (f(pos($x))==4) {print "ok 3\n"} else {print "not ok 3\n";}
 
+# Is pos() set inside //g? (bug id 19990615.008)
+$x = "test string?"; $x =~ s/\w/pos($x)/eg;
+print "not " unless $x eq "0123 5678910?";
+print "ok 4\n";
+
+
+