From: Nicholas Clark Date: Thu, 30 Mar 2006 20:55:17 +0000 (+0000) Subject: Localising hash slices with UTF-8 encoded keys was also buggy. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=919acde01827c5ad450bac06c554f5a69eb06cef;p=p5sagit%2Fp5-mst-13.2.git Localising hash slices with UTF-8 encoded keys was also buggy. (See also change 27637) p4raw-id: //depot/perl@27638 --- diff --git a/pp.c b/pp.c index 99f0b06..467ef22 100644 --- 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); } } } diff --git a/t/op/local.t b/t/op/local.t index bc24657..ca44607 100755 --- a/t/op/local.t +++ b/t/op/local.t @@ -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"); +}