Skip to content

Make :utf8 an actually validating layer #23342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: blead
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpan/CPAN-Meta-YAML/t/11_read_string.t
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ subtest 'invalid UTF-8' => sub {
# get invalid UTF-8 by reading Latin-1 with lax :utf8 layer
my $string = do {
local $SIG{__WARN__} = sub {};
slurp( test_data_file('latin1.yml'), ":utf8" );
slurp( test_data_file('latin1.yml'), ":utf8_lax" );
};
my $obj = eval { CPAN::Meta::YAML->read_string($string); };
is( $obj, undef, "read_string should return undef" );
error_like( qr/invalid UTF-8 string/,
error_like( qr/UTF-8/,
"Got expected error about invalid UTF-8 string"
);
};
Expand Down
23 changes: 8 additions & 15 deletions lib/PerlIO.pm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package PerlIO;

our $VERSION = '1.12';
our $VERSION = '1.13';

# Map layer name to package that defines it
our %alias;
Expand Down Expand Up @@ -175,17 +175,10 @@ between valid UTF-8 bytes and valid Unicode characters.

=item :bytes

This is the inverse of the C<:utf8> pseudo-layer. It turns off the flag
on the layer below so that data read from it is considered to
be Perl's internal downgraded encoding, thus interpreted as the native
single-byte encoding of Latin-1 or EBCDIC. Likewise on output Perl will
warn if a "wide" character (a codepoint not in the range 0..255) is
written to a such a stream.

This is very dangerous to push on a handle using an C<:encoding> layer,
as such a layer assumes to be working with Perl's internal upgraded
encoding, so you will likely get a mangled result. Instead use C<:raw> or
C<:pop> to remove encoding layers.
This removes all layers that do unicode IO, such as C<:utf8> and
C<:encoding>. It ensures that data read from it is considered to be
"octets" i.e. characters in the range 0..255 only. Likewise on output perl
will warn if a "wide" character is written to a such a stream.

=item :raw

Expand All @@ -203,9 +196,9 @@ to add C<:perlio> to the PERLIO environment variable, or open the handle
explicitly with that layer, to replace the platform default of C<:crlf>.

The implementation of C<:raw> is as a pseudo-layer which when "pushed"
pops itself and then any layers which would modify the binary data stream.
(Undoing C<:utf8> and C<:crlf> may be implemented by clearing flags
rather than popping layers but that is an implementation detail.)
pops itself and then any layers which do not declare themselves as suitable
for binary data. (Undoing :crlf is implemented by clearing a flag rather
than popping the layer but that is an implementation detail.)

As a consequence of the fact that C<:raw> normally pops layers,
it usually only makes sense to have it as the only or first element in
Expand Down
Loading
Loading