Fix utf8::is_utf8 to respect GMAGIC (e.g. $1)
gfx [Sun, 25 Apr 2010 20:02:09 +0000 (22:02 +0200)]
MANIFEST
t/op/utf8magic.t [new file with mode: 0644]
universal.c

index 65c7755..f774db8 100644 (file)
--- 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 (file)
index 0000000..2c915b7
--- /dev/null
@@ -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;
index ce56d0b..006baa2 100644 (file)
@@ -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