From: gfx Date: Sun, 25 Apr 2010 20:02:09 +0000 (+0200) Subject: Fix utf8::is_utf8 to respect GMAGIC (e.g. $1) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=76f730215a330c9eedad075cf13e470e97f62846;p=p5sagit%2Fp5-mst-13.2.git Fix utf8::is_utf8 to respect GMAGIC (e.g. $1) --- diff --git a/MANIFEST b/MANIFEST index 65c7755..f774db8 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 0000000..2c915b7 --- /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 ce56d0b..006baa2 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