op.c: Flag named methods if they are in UTF-8.
authorBrian Fraser <fraserbn@gmail.com>
Mon, 26 Sep 2011 16:21:23 +0000 (09:21 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 6 Oct 2011 20:01:07 +0000 (13:01 -0700)
MANIFEST
op.c
t/uni/method.t [new file with mode: 0644]

index 0dad869..48b2466 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -5244,6 +5244,7 @@ t/uni/gv.t                        See if Unicode GVs work.
 t/uni/latin2.t                 See if Unicode in latin2 works
 t/uni/lex_utf8.t               See if Unicode in lexer works
 t/uni/lower.t                  See if Unicode casing works
+t/uni/method.t                 See if Unicode methods work
 t/uni/overload.t               See if Unicode overloading works
 t/uni/parser.t                 See if Unicode in the parser works in edge cases.
 t/uni/sprintf.t                        See if Unicode sprintf works
diff --git a/op.c b/op.c
index 2a58c28..f5654cd 100644 (file)
--- a/op.c
+++ b/op.c
@@ -8337,7 +8337,7 @@ Perl_ck_method(pTHX_ OP *o)
        if (!(strchr(method, ':') || strchr(method, '\''))) {
            OP *cmop;
            if (!SvREADONLY(sv) || !SvFAKE(sv)) {
-               sv = newSVpvn_share(method, SvCUR(sv), 0);
+               sv = newSVpvn_share(method, SvUTF8(sv) ? -SvCUR(sv) : SvCUR(sv), 0);
            }
            else {
                kSVOP->op_sv = NULL;
diff --git a/t/uni/method.t b/t/uni/method.t
new file mode 100644 (file)
index 0000000..fdefbf5
--- /dev/null
@@ -0,0 +1,40 @@
+#!./perl -w
+
+#
+# test method calls and autoloading.
+#
+
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = qw(. ../lib);
+    require "test.pl";
+}
+
+use strict;
+use utf8;
+use open qw( :utf8 :std );
+no warnings 'once';
+
+plan(tests => 15);
+
+#Can't use bless yet, as it might not be clean
+
+sub F::b { ::is shift, "F";  "UTF8 meth"       }
+sub F::b { ::is shift, "F";  "UTF8 Stash"     }
+sub F::b { ::is shift, "F"; "UTF8 Stash&meth" }
+
+is(F->b, "UTF8 meth", "If the method is in UTF-8, lookup works through explicitly named methods");
+is(F->${\"b"}, "UTF8 meth", '..as does for ->${\""}');
+eval { F->${\"b\0nul"} };
+ok $@, "If the method is in UTF-8, lookup is nul-clean";
+
+is(F->b, "UTF8 Stash", "If the stash is in UTF-8, lookup works through explicitly named methods");
+is(F->${\"b"}, "UTF8 Stash", '..as does for ->${\""}');
+eval { F->${\"b\0nul"} };
+ok $@, "If the stash is in UTF-8, lookup is nul-clean";
+
+is(F->b, "UTF8 Stash&meth", "If both stash and method are in UTF-8, lookup works through explicitly named methods");
+is(F->${\"b"}, "UTF8 Stash&meth", '..as does for ->${\""}');
+eval { F->${\"b\0nul"} };
+ok $@, "Even if both stash and method are in UTF-8, lookup is nul-clean";
+