This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #96008] use and require are affected by the open pragma
authorBrian Fraser <fraserbn@gmail.com>
Fri, 23 Sep 2011 05:31:46 +0000 (22:31 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 23 Sep 2011 05:31:46 +0000 (22:31 -0700)
% perl -e 'print "package F;\n # \xF1\n;1;"' > x.pl
% perl '-Mopen=:encoding(utf8)' -e 'require "x.pl"'
utf8 "\xF1" does not map to Unicode at x.pl line 1.

Bit of a surprising discovery; Turns out that passing a single ":" for
the layers skips the fetch from the context layers:
perl -wE 'use open qw( :encoding(UTF-8) ); open my $fh, "<:", "etc"; say PerlIO::get_layers($fh);'

That will only get the relevant default layers, while removing the
colons makes it work as usual -- So we can abuse this (mis)feature to
fix the bug.

pp_ctl.c

index 52b0682..054de67 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3634,7 +3634,7 @@ S_check_type_and_open(pTHX_ SV *name)
     }
 
 #if !defined(PERLIO_IS_STDIO) && !defined(USE_SFIO)
-    return PerlIO_openn(aTHX_ NULL, PERL_SCRIPT_MODE, -1, 0, 0, NULL, 1, &name);
+    return PerlIO_openn(aTHX_ ":", PERL_SCRIPT_MODE, -1, 0, 0, NULL, 1, &name);
 #else
     return PerlIO_open(p, PERL_SCRIPT_MODE);
 #endif