summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgfx <gfuji@cpan.org>2010-04-25 22:02:09 +0200
committerVincent Pit <perl@profvince.com>2010-05-06 20:57:33 +0200
commit6af88f0d661fafdd0401bc92bf25c253c47b34d4 (patch)
tree19372d5184d5ad1efe1d7b560f416c21fbc51ded
parent115e83076034aec9315114fb123b0003b5664a15 (diff)
downloadperl-6af88f0d661fafdd0401bc92bf25c253c47b34d4.tar.gz
Fix utf8::is_utf8 to respect GMAGIC (e.g. $1)
-rw-r--r--MANIFEST1
-rw-r--r--t/op/utf8magic.t19
-rw-r--r--universal.c3
3 files changed, 22 insertions, 1 deletions
diff --git a/MANIFEST b/MANIFEST
index 38144c8935..4e21c708cf 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -4501,6 +4501,7 @@ t/op/unshift.t See if unshift works
t/op/upgrade.t See if upgrading and assigning scalars works
t/op/utf8cache.t Tests malfunctions of utf8 cache
t/op/utf8decode.t See if UTF-8 decoding works
+t/op/utf8magic.t See if utf8:: functions handle magic variables
t/op/utfhash.t See if utf8 keys in hashes behave
t/op/utftaint.t See if utf8 and taint work together
t/op/vec.t See if vectors work
diff --git a/t/op/utf8magic.t b/t/op/utf8magic.t
new file mode 100644
index 0000000000..2c915b716e
--- /dev/null
+++ b/t/op/utf8magic.t
@@ -0,0 +1,19 @@
+#!perl -w
+use strict;
+use Test::More;
+
+my $str = "\x{99f1}\x{99dd}"; # "camel" in Japanese kanji
+$str =~ /(.)/;
+
+ok utf8::is_utf8($1), "is_utf8(unistr)";
+scalar "$1"; # invoke SvGETMAGIC
+ok utf8::is_utf8($1), "is_utf8(unistr)";
+
+utf8::encode($str); # off the utf8 flag
+$str =~ /(.)/;
+
+ok !utf8::is_utf8($1), "is_utf8(bytes)";
+scalar "$1"; # invoke SvGETMAGIC
+ok !utf8::is_utf8($1), "is_utf8(bytes)";
+
+done_testing;
diff --git a/universal.c b/universal.c
index ce56d0becd..006baa2fed 100644
--- a/universal.c
+++ b/universal.c
@@ -794,7 +794,8 @@ XS(XS_utf8_is_utf8)
if (items != 1)
croak_xs_usage(cv, "sv");
else {
- const SV * const sv = ST(0);
+ SV * const sv = ST(0);
+ SvGETMAGIC(sv);
if (SvUTF8(sv))
XSRETURN_YES;
else