diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-08-30 18:01:27 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-08-30 18:18:13 -0700 |
commit | 7d1328bb7c26d556809b1aed184cec377b18f20c (patch) | |
tree | 8b5067a3cef208222fda2304bf74c884f6bb8f8e /t/op/utf8cache.t | |
parent | 4785469e43ed59eb07455c31ce1079ada2c9f91f (diff) | |
download | perl-7d1328bb7c26d556809b1aed184cec377b18f20c.tar.gz |
[perl #114410] Reset utf8 pos cache on get
If a scalar is gmagical, then the string buffer could change without
the utf8 pos cache being updated.
So it should respond to get-magic, not just set-magic. Actually add-
ing get-magic to the utf8 magic vtable would cause all scalars with
this magic to be flagged gmagical. Instead, in magic_get, we can call
magic_setutf8.
Diffstat (limited to 't/op/utf8cache.t')
-rw-r--r-- | t/op/utf8cache.t | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/t/op/utf8cache.t b/t/op/utf8cache.t index f8698c8fa1..a9e88a6e05 100644 --- a/t/op/utf8cache.t +++ b/t/op/utf8cache.t @@ -9,7 +9,7 @@ BEGIN { use strict; -plan(tests => 2); +plan(tests => 5); SKIP: { skip_without_dynamic_extension("Devel::Peek"); @@ -51,3 +51,29 @@ unlike($_, qr{ $utf8magic $utf8magic }x); } pass("quadratic pos"); } + +# Get-magic can reallocate the PV. Check that the cache is reset in +# such cases. + +# Regexp vars +"\x{100}" =~ /(.+)/; +() = substr $1, 0, 1; +"a\x{100}" =~ /(.+)/; +is ord substr($1, 1, 1), 0x100, 'get-magic resets utf8cache on match vars'; + +# Substr lvalues +my $x = "a\x{100}"; +my $l = \substr $x, 0; +() = substr $$l, 1, 1; +substr $x, 0, 1, = "\x{100}"; +is ord substr($$l, 1, 1), 0x100, 'get-magic resets utf8cache on LVALUEs'; + +# defelem magic +my %h; +sub { + $_[0] = "a\x{100}"; + () = ord substr $_[0], 1, 1; + $h{k} = "\x{100}"x2; + is ord substr($_[0], 1, 1), 0x100, + 'get-magic resets uf8cache on defelems'; +}->($h{k}); |