X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Debbugs%2FUTF8.pm;h=01351f3668f04e2e33704eb672300006bf656579;hb=8e2468e4725d9784c5e99915cee75c3cc41903cf;hp=0ad284df16a6d37794098c5c67de37b70613b835;hpb=d4b9a1bfe03c6ec1451c8f9178bb5a7458e9ae3e;p=debbugs.git diff --git a/Debbugs/UTF8.pm b/Debbugs/UTF8.pm index 0ad284d..01351f3 100644 --- a/Debbugs/UTF8.pm +++ b/Debbugs/UTF8.pm @@ -28,7 +28,7 @@ charsets to UTF8. use warnings; use strict; use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT); -use base qw(Exporter); +use Exporter qw(import); BEGIN{ $VERSION = 1.00; @@ -154,6 +154,10 @@ sub convert_to_utf8 { if ($charset eq 'RAW') { croak("Charset must not be raw when calling convert_to_utf8"); } + ## if the charset is unknown or unknown 8 bit, assume that it's UTF-8. + if ($charset =~ /unknown/i) { + $charset = 'UTF-8' + } my $iconv_converter; eval { $iconv_converter = Text::Iconv->new($charset,"UTF-8") or @@ -179,11 +183,9 @@ sub convert_to_utf8 { # if there's an à (0xC3), it's probably something # horrible, and we shouldn't try to convert it. if (defined $call_back_data and $call_back_data !~ /\x{C3}/) { - warn "failed to convert to utf8 (charset: $charset, data: $data), but succeeded with ISO8859-1: ".encode_utf8($call_back_data); return $call_back_data; } } - warn "failed to convert to utf8 (charset: $charset, data: $data)"; # Fallback to encode, which will probably also fail. return __fallback_convert_to_utf8($data,$charset); } @@ -202,6 +204,10 @@ sub __fallback_convert_to_utf8 { } # lets assume everything that doesn't have a charset is utf8 $charset //= 'utf8'; + ## if the charset is unknown, assume it's UTF-8 + if ($charset =~ /unknown/i) { + $charset = 'utf8'; + } my $result; eval { $result = decode($charset,$data,0);