Skip to content

Commit

Permalink
[perl #96008] use and require are affected by the open pragma
Browse files Browse the repository at this point in the history
% 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.
  • Loading branch information
Hugmeir authored and Father Chrysostomos committed Sep 23, 2011
1 parent 69dc7e4 commit 639dfab
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pp_ctl.c
Expand Up @@ -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
Expand Down

0 comments on commit 639dfab

Please sign in to comment.