Change 33580 by [EMAIL PROTECTED] on 2008/03/26 21:05:20

        The offset for pos is stored as bytes, and converted to (Unicode)
        character position when read, if needed. The code for setting pos
        inside subst was incorrectly converting to character position before
        storing the value. This code appears to have been buggy since it was
        added in 2000 in change 7562.

Affected files ...

... //depot/perl/pp_ctl.c#688 edit
... //depot/perl/t/op/subst.t#50 edit

Differences ...

==== //depot/perl/pp_ctl.c#688 (text) ====
Index: perl/pp_ctl.c
--- perl/pp_ctl.c#687~33356~    2008-02-23 00:19:00.000000000 -0800
+++ perl/pp_ctl.c       2008-03-26 14:05:20.000000000 -0700
@@ -298,7 +298,6 @@
     { /* Update the pos() information. */
        SV * const sv = cx->sb_targ;
        MAGIC *mg;
-       I32 i;
        SvUPGRADE(sv, SVt_PVMG);
        if (!(mg = mg_find(sv, PERL_MAGIC_regex_global))) {
 #ifdef PERL_OLD_COPY_ON_WRITE
@@ -308,10 +307,7 @@
            mg = sv_magicext(sv, NULL, PERL_MAGIC_regex_global, &PL_vtbl_mglob,
                             NULL, 0);
        }
-       i = m - orig;
-       if (DO_UTF8(sv))
-           sv_pos_b2u(sv, &i);
-       mg->mg_len = i;
+       mg->mg_len = m - orig;
     }
     if (old != rx)
        (void)ReREFCNT_inc(rx);

==== //depot/perl/t/op/subst.t#50 (xtext) ====
Index: perl/t/op/subst.t
--- perl/t/op/subst.t#49~29619~ 2006-12-23 08:15:50.000000000 -0800
+++ perl/t/op/subst.t   2008-03-26 14:05:20.000000000 -0700
@@ -7,7 +7,7 @@
 }
 
 require './test.pl';
-plan( tests => 136 );
+plan( tests => 139 );
 
 $x = 'foo';
 $_ = "x";
@@ -583,3 +583,11 @@
     is($want,$_,"RT#17542");
 }
 
+{
+    my @tests = ('ABC', "\xA3\xA4\xA5", "\x{410}\x{411}\x{412}");
+    foreach (@tests) {
+       my $id = ord $_;
+       s/./pos/ge;
+       is($_, "012", "RT#52104: $id");
+    }
+}
End of Patch.

Reply via email to