This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #33752] B::Deparse fails with utf8 and our
authorFather Chrysostomos <sprout@cpan.org>
Tue, 19 Oct 2010 00:57:25 +0000 (17:57 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 21 Oct 2010 12:53:03 +0000 (05:53 -0700)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This commit makes B::Deparse support code like ‘our $ḟōō’. Currently,
an ‘our’ variable whose name is an octet sequence that does not consist
of (\w|::)+ can only be a UTF8 variable name.

When the pad is made to support UTF8 properly, this may need to
be changed.

dist/B-Deparse/Deparse.pm
dist/B-Deparse/t/deparse.t

index b98b1fb..7ea5437 100644 (file)
@@ -1041,9 +1041,11 @@ sub maybe_local {
        and not $self->{'avoid_local'}{$$op}) {
        my $our_local = ($op->private & OPpLVAL_INTRO) ? "local" : "our";
        if( $our_local eq 'our' ) {
-           # XXX This assertion fails code with non-ASCII identifiers,
-           # like ./ext/Encode/t/jperl.t
-           die "Unexpected our($text)\n" unless $text =~ /^\W(\w+::)*\w+\z/;
+           if ( $text !~ /^\W(\w+::)*\w+\z/
+            and !utf8::decode($text) || $text !~ /^\W(\w+::)*\w+\z/
+           ) {
+               die "Unexpected our($text)\n";
+           }
            $text =~ s/(\w+::)+//;
        }
         if (want_scalar($op)) {
index 0fc3b6c..4b94d4a 100644 (file)
@@ -17,7 +17,7 @@ BEGIN {
     require feature;
     feature->import(':5.10');
 }
-use Test::More tests => 90;
+use Test::More tests => 91;
 use Config ();
 
 use B::Deparse;
@@ -166,6 +166,19 @@ eval <<EOFCODE and test($x);
    1
 EOFCODE
 
+# [perl #33752]
+{
+  my $code = <<"EOCODE";
+{
+    our \$\x{1e1f}\x{14d}\x{14d};
+}
+EOCODE
+  my $deparsed
+   = $deparse->coderef2text(eval "sub { our \$\x{1e1f}\x{14d}\x{14d} }" );
+  s/$ \n//x for $deparsed, $code;
+  is $deparsed, $code, 'our $funny_Unicode_chars';
+}
+
 __DATA__
 # 2
 1;