Localising hash slices with UTF-8 encoded keys was also buggy.
authorNicholas Clark <nick@ccl4.org>
Thu, 30 Mar 2006 20:55:17 +0000 (20:55 +0000)
committerNicholas Clark <nick@ccl4.org>
Thu, 30 Mar 2006 20:55:17 +0000 (20:55 +0000)
(See also change 27637)

p4raw-id: //depot/perl@27638

pp.c
t/op/local.t

diff --git a/pp.c b/pp.c
index 99f0b06febae774675b37234db4419ef28ed51d3..467ef225d2d7f16fed5684bd5be0d2f8d7715d5d 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -3887,7 +3887,8 @@ PP(pp_hslice)
                    else {
                        STRLEN keylen;
                        const char *key = SvPV_const(keysv, keylen);
-                       SAVEDELETE(hv, savepvn(key,keylen), keylen);
+                       SAVEDELETE(hv, savepvn(key,keylen),
+                                  SvUTF8(keysv) ? -keylen : keylen);
                    }
                }
             }
index bc24657a54f034e8dd9c242fd1e943afb01fc3ee..ca446077307070b200d3955864795647381c4b24 100755 (executable)
@@ -4,7 +4,7 @@ BEGIN {
     chdir 't' if -d 't';
     require './test.pl';
 }
-plan tests => 104;
+plan tests => 113;
 
 my $list_assignment_supported = 1;
 
@@ -392,3 +392,26 @@ sub f { ok(0 == $[); }
     is($h{"\243"}, "pound");
     is($h{"\302\240"}, "octects");
 }
+
+# And with slices
+{
+    my %h;
+    $h{"\243"} = "pound";
+    $h{"\302\240"} = "octects";
+    is(scalar keys %h, 2);
+    {
+       my $unicode = chr 256;
+       my $ambigous = "\240" . $unicode;
+       chop $ambigous;
+       local @h{$unicode, $ambigous} = (256, 160);
+
+       is(scalar keys %h, 4);
+       is($h{"\243"}, "pound");
+       is($h{$unicode}, 256);
+       is($h{$ambigous}, 160);
+       is($h{"\302\240"}, "octects");
+    }
+    is(scalar keys %h, 2);
+    is($h{"\243"}, "pound");
+    is($h{"\302\240"}, "octects");
+}