Subject: | Still can't turn off "does not map to Unicode" warnings |
This is related to #88592.
Encode still fails to honour the caller’s warning settings in some cases.
As noted in perl ticket #128788, this script emits a warning erroneously:
use open qw( :std :utf8 );
use strict;
use warnings;
no warnings 'utf8';
my $bytes = "Test\x{E5}End";
my $fn = 'test.txt';
open ( my $fh, '>:raw', $fn ) or die "Could not open file '$fn': $!";
print $fh $bytes;
close $fh;
open ( $fh, "<:encoding(utf-8)", $fn ) or die "Could not open file '$fn':
$!";
my $str = do { local $/; <$fh> };
close $fh;
The attached one-line patch to Encode.xs fixes it. It is not intended to be a final patch, but a diagnostic tool. I simply used a C debugger to trace where the warning was coming from. I don’t know whether there is other similar code in Encode.xs that needs similar treatment.
Subject: | open_IcjZZ4h6.txt |
diff --git a/Encode.xs b/cpan/Encode/Encode.xs
index cd7f7d1..403ba21 100644
--- a/Encode.xs
+++ b/Encode.xs
@@ -400,7 +400,7 @@ process_utf8(pTHX_ SV* dst, U8* s, U8* e, SV *check_sv,
else
Perl_croak(aTHX_ ERR_DECODE_NOMAP, "utf8", uv);
}
- if (check & ENCODE_WARN_ON_ERR){
+ if (check & ENCODE_WARN_ON_ERR && ckWARN_d(WARN_UTF8)){
if (encode)
Perl_warner(aTHX_ packWARN(WARN_UTF8),
ERR_ENCODE_NOMAP, uv, "utf8");