diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-05-29 14:21:06 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-05-29 14:46:22 -0700 |
commit | 40f11004fb3b5fa1cd207a20090df837d721b736 (patch) | |
tree | 6a34379b467f76b48ac57cc85685ec0c104e9848 /lib/utf8.t | |
parent | 694cf0d2097096aceb05356229e210423cd909c2 (diff) | |
download | perl-40f11004fb3b5fa1cd207a20090df837d721b736.tar.gz |
[perl #91834] utf8::decode does not respect copy-on-write
utf8::decode was not respecting copy-on-write, but simply modify-
ing the PV (the scalar’s string buffer) in place, causing problems
with hashes:
my $name = "\x{c3}\x{b3}";
my ($k1) = keys %{ { $name=>undef } };
my $k2 = $name;
utf8::decode($k1);
utf8::decode($k2);
print "k1 eq k2 = '", $k1 eq $k2, "'\n";
my $h = { $k1 => 1, $k2 => 2 };
print "{k1} '", $h->{$k1}, "'\n";
print "{k2} '", $h->{$k2}, "'\n";
This example (from the RT ticket) shows that there were two hash ele-
ments with the same key.
As of this commit, the hash only has one element.
Diffstat (limited to 'lib/utf8.t')
-rw-r--r-- | lib/utf8.t | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/utf8.t b/lib/utf8.t index ae81ccdc46..b13bb5377d 100644 --- a/lib/utf8.t +++ b/lib/utf8.t @@ -427,6 +427,18 @@ SKIP: { } { + # Make sure utf8::decode respects copy-on-write [perl #91834]. + # Hash keys are the easiest way to test this. + my $name = "\x{c3}\x{b3}"; + my ($k1) = keys %{ { $name=>undef } }; + my $k2 = $name; + utf8::decode($k1); + utf8::decode($k2); + my $h = { $k1 => 1, $k2 => 2 }; + is join('', keys $h), $k2, 'utf8::decode respects copy-on-write'; +} + +{ my $a = "456\xb6"; utf8::upgrade($a); |