From 79edd281f8c83e9c268b297d60469edfed7b999a Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Mon, 26 Sep 2011 09:21:23 -0700 Subject: [PATCH] op.c: Flag named methods if they are in UTF-8. --- MANIFEST | 1 + op.c | 2 +- t/uni/method.t | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 t/uni/method.t diff --git a/MANIFEST b/MANIFEST index 0dad869..48b2466 100644 --- 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 --- 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 index 0000000..fdefbf5 --- /dev/null +++ b/t/uni/method.t @@ -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"; + -- 2.7.4