This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make strict vars respect ‘package ĵ; *ĵ::bar = [];’
authorFather Chrysostomos <sprout@cpan.org>
Mon, 9 Apr 2012 06:04:38 +0000 (23:04 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 20 Apr 2012 03:09:12 +0000 (20:09 -0700)
In this particular case, the name of the current package in UTF-8 (it
cannot be expressed in Latin-1) is the same byte sequence as the name
of the package being assigned to in Latin-1.

Some of the logic in stashpv_hvname_match was faulty.  It worked for
a Latin-1 current package assigning to a glob in a UTF-8 package, but
not the other way around.

t/lib/strict/vars
util.c

index 568d991..b8c6d1f 100644 (file)
@@ -554,3 +554,12 @@ package Foo;
 use strict;
 eval 'package foo; @bar = 1' or die;
 EXPECT
+########
+# UTF8 and Latin1 package names equivalent at the byte level
+use utf8;
+# ĵ in UTF-8 is the same as Äµ in Latin-1
+package ĵ;
+*ĵ::bar = [];
+use strict;
+eval 'package Äµ; @bar = 1' or die;
+EXPECT
diff --git a/util.c b/util.c
index 500bef5..716944d 100644 (file)
--- a/util.c
+++ b/util.c
@@ -5861,7 +5861,7 @@ Perl_stashpv_hvname_match(pTHX_ const COP *c, const HV *hv)
 
     if (!stashpv || !name)
        return stashpv == name;
-    if ( HvNAMEUTF8(hv) && !utf8 ) {
+    if ( !HvNAMEUTF8(hv) != !utf8 ) {
         if (utf8) {
             return (bytes_cmp_utf8(
                         (const U8*)stashpv, len,