From: Don Armstrong Date: Thu, 4 Apr 2013 17:25:02 +0000 (-0700) Subject: Text::Iconv has a bug where it fails to reset the converter with a call to iconv... X-Git-Tag: release/2.6.0~280^2~7 X-Git-Url: https://git.donarmstrong.com/?p=debbugs.git;a=commitdiff_plain;h=94c99b69df4bb1d9b4859b4796c99d0a4d9d4ae4 Text::Iconv has a bug where it fails to reset the converter with a call to iconv(cd,NULL,(size_t) 0,NULL,(size_t) 0) if it fails during conversion; always create a new Text::Iconv object to work around this --- diff --git a/Debbugs/UTF8.pm b/Debbugs/UTF8.pm index c90cedf..bc3a0fa 100644 --- a/Debbugs/UTF8.pm +++ b/Debbugs/UTF8.pm @@ -143,8 +143,6 @@ sub decode_utf8_safely{ =cut -our %iconv_converters; - sub convert_to_utf8 { my ($data,$charset,$internal_call) = @_; $internal_call //= 0; @@ -156,28 +154,22 @@ sub convert_to_utf8 { if ($charset eq 'RAW') { croak("Charset must not be raw when calling convert_to_utf8"); } - if (not defined $iconv_converters{$charset}) { - eval { - $iconv_converters{$charset} = Text::Iconv->new($charset,"UTF-8") or - die "Unable to create converter for '$charset'"; - }; - if ($@) { - return undef if $internal_call; - warn $@; - # We weren't able to create the converter, so use Encode - # instead - return __fallback_convert_to_utf8($data,$charset); - } - } - if (not defined $iconv_converters{$charset}) { + my $iconv_converter; + eval { + $iconv_converter = Text::Iconv->new($charset,"UTF-8") or + die "Unable to create converter for '$charset'"; + }; + if ($@) { return undef if $internal_call; - warn "The converter for $charset wasn't created properly somehow!"; + warn $@; + # We weren't able to create the converter, so use Encode + # instead return __fallback_convert_to_utf8($data,$charset); } - my $converted_data = $iconv_converters{$charset}->convert($data); + my $converted_data = $iconv_converter->convert($data); # if the conversion failed, retval will be undefined or perhaps # -1. - my $retval = $iconv_converters{$charset}->retval(); + my $retval = $iconv_converter->retval(); if (not defined $retval or $retval < 0 ) {