summaryrefslogtreecommitdiff
path: root/systems/texlive/tlnet/tlpkg/tlperl/lib/Encode.pm
diff options
context:
space:
mode:
Diffstat (limited to 'systems/texlive/tlnet/tlpkg/tlperl/lib/Encode.pm')
-rw-r--r--systems/texlive/tlnet/tlpkg/tlperl/lib/Encode.pm52
1 files changed, 28 insertions, 24 deletions
diff --git a/systems/texlive/tlnet/tlpkg/tlperl/lib/Encode.pm b/systems/texlive/tlnet/tlpkg/tlperl/lib/Encode.pm
index d3eb3c1b11..8a2727fc44 100644
--- a/systems/texlive/tlnet/tlpkg/tlperl/lib/Encode.pm
+++ b/systems/texlive/tlnet/tlpkg/tlperl/lib/Encode.pm
@@ -1,5 +1,5 @@
#
-# $Id: Encode.pm,v 3.08 2020/12/02 01:27:44 dankogai Exp $
+# $Id: Encode.pm,v 3.19 2022/08/04 04:42:30 dankogai Exp $
#
package Encode;
use strict;
@@ -7,7 +7,7 @@ use warnings;
use constant DEBUG => !!$ENV{PERL_ENCODE_DEBUG};
our $VERSION;
BEGIN {
- $VERSION = sprintf "%d.%02d", q$Revision: 3.08 $ =~ /(\d+)/g;
+ $VERSION = sprintf "%d.%02d", q$Revision: 3.19 $ =~ /(\d+)/g;
require XSLoader;
XSLoader::load( __PACKAGE__, $VERSION );
}
@@ -65,8 +65,8 @@ require Encode::Config;
eval {
local $SIG{__DIE__};
local $SIG{__WARN__};
- local @INC = @INC || ();
- pop @INC if $INC[-1] eq '.';
+ local @INC = @INC;
+ pop @INC if @INC && $INC[-1] eq '.';
require Encode::ConfigLocal;
};
@@ -202,18 +202,6 @@ if ($ON_EBCDIC) {
$_[1] = '' if $chk;
return $res;
}
-} else {
- package Encode::Internal;
- use parent 'Encode::Encoding';
- my $obj = bless { Name => "Internal" } => "Encode::Internal";
- Encode::define_encoding($obj, 'Unicode');
- sub decode {
- my ( undef, $str, $chk ) = @_;
- utf8::upgrade($str);
- $_[1] = '' if $chk;
- return $str;
- }
- *encode = \&decode;
}
{
@@ -499,19 +487,25 @@ followed by C<encode> as follows:
$octets = encode_utf8($string);
+B<WARNING>: L<This function can produce invalid UTF-8!|/UTF-8 vs. utf8 vs. UTF8>
+Do not use it for data exchange.
+Unless you want Perl's older "lax" mode, prefer
+C<$octets = encode("UTF-8", $string)>.
+
Equivalent to C<$octets = encode("utf8", $string)>. The characters in
$string are encoded in Perl's internal format, and the result is returned
as a sequence of octets. Because all possible characters in Perl have a
(loose, not strict) utf8 representation, this function cannot fail.
-B<WARNING>: do not use this function for data exchange as it can produce
-not strict utf8 $octets! For strictly valid UTF-8 output use
-C<$octets = encode("UTF-8", $string)>.
-
=head3 decode_utf8
$string = decode_utf8($octets [, CHECK]);
+B<WARNING>: L<This function accepts invalid UTF-8!|/UTF-8 vs. utf8 vs. UTF8>
+Do not use it for data exchange.
+Unless you want Perl's older "lax" mode, prefer
+C<$string = decode("UTF-8", $octets [, CHECK])>.
+
Equivalent to C<$string = decode("utf8", $octets [, CHECK])>.
The sequence of octets represented by $octets is decoded
from (loose, not strict) utf8 into a sequence of logical characters.
@@ -519,10 +513,6 @@ Because not all sequences of octets are valid not strict utf8,
it is quite possible for this function to fail.
For CHECK, see L</"Handling Malformed Data">.
-B<WARNING>: do not use this function for data exchange as it can produce
-$string with not strict utf8 representation! For strictly valid UTF-8
-$string representation use C<$string = decode("UTF-8", $octets [, CHECK])>.
-
B<CAVEAT>: the input I<$octets> might be modified in-place depending on
what is set in CHECK. See L</LEAVE_SRC> if you want your inputs to be
left unchanged.
@@ -927,6 +917,20 @@ important distinction between C<"UTF-8"> and C<"utf8">.
encode("utf8", "\x{FFFF_FFFF}", 1); # okay
encode("UTF-8", "\x{FFFF_FFFF}", 1); # croaks
+This distinction is also important for decoding. In the following,
+C<$s> stores character U+200000, which exceeds UTF-8's allowed range.
+C<$s> thus stores an invalid Unicode code point:
+
+ $s = decode("utf8", "\xf8\x88\x80\x80\x80");
+
+C<"UTF-8">, by contrast, will either coerce the input to something valid:
+
+ $s = decode("UTF-8", "\xf8\x88\x80\x80\x80"); # U+FFFD
+
+.. or croak:
+
+ decode("UTF-8", "\xf8\x88\x80\x80\x80", FB_CROAK|LEAVE_SRC);
+
In the C<Encode> module, C<"UTF-8"> is actually a canonical name for
C<"utf-8-strict">. That hyphen between the C<"UTF"> and the C<"8"> is
critical; without it, C<Encode> goes "liberal" and (perhaps overly-)permissive: