Bug 1511950 - Add missing calls to GetCharsetAlias() to take Thunderbird's aliases into account. r=mkmelin

This commit is contained in:
Jorg K 2018-12-05 11:27:59 +01:00
Родитель fd2a626b0e
Коммит ef60e0a0cf
2 изменённых файлов: 30 добавлений и 9 удалений

Просмотреть файл

@ -72,20 +72,32 @@ nsresult nsMsgI18NConvertToUnicode(const nsACString& aCharset,
outString.Truncate();
return NS_OK;
}
else if (aCharset.IsEmpty()) {
if (aCharset.IsEmpty()) {
// Despite its name, it also works for Latin-1.
CopyASCIItoUTF16(inString, outString);
return NS_OK;
}
else if (aCharset.Equals("UTF-7", nsCaseInsensitiveCStringComparator())) {
// Special treatment for decoding UTF-7 since it's not handled by encoding_rs.
return CopyUTF7toUTF16(inString, outString);
}
else if (aCharset.Equals("UTF-8", nsCaseInsensitiveCStringComparator())) {
if (aCharset.Equals("UTF-8", nsCaseInsensitiveCStringComparator())) {
return UTF_8_ENCODING->DecodeWithBOMRemoval(inString, outString);
}
auto encoding = mozilla::Encoding::ForLabelNoReplacement(aCharset);
// Look up Thunderbird's special aliases from charsetalias.properties.
nsresult rv;
nsCOMPtr<nsICharsetConverterManager> ccm =
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCString newCharset;
rv = ccm->GetCharsetAlias(PromiseFlatCString(aCharset).get(), newCharset);
NS_ENSURE_SUCCESS(rv, rv);
if (newCharset.Equals("UTF-7", nsCaseInsensitiveCStringComparator())) {
// Special treatment for decoding UTF-7 since it's not handled by encoding_rs.
return CopyUTF7toUTF16(inString, outString);
}
auto encoding = mozilla::Encoding::ForLabelNoReplacement(newCharset);
if (!encoding)
return NS_ERROR_UCONV_NOCONV;
return encoding->DecodeWithoutBOMHandlingAndWithoutReplacement(inString,

Просмотреть файл

@ -811,7 +811,16 @@ int ConvertToUTF8(const char *stringToUse, int32_t inLength,
{
nsresult rv = NS_OK;
if (PL_strcasecmp(input_charset, "UTF-7") == 0) {
// Look up Thunderbird's special aliases from charsetalias.properties.
nsCOMPtr<nsICharsetConverterManager> ccm =
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, -1);
nsCString newCharset;
rv = ccm->GetCharsetAlias(input_charset, newCharset);
NS_ENSURE_SUCCESS(rv, -1);
if (newCharset.Equals("UTF-7", nsCaseInsensitiveCStringComparator())) {
nsAutoString utf16;
rv = CopyUTF7toUTF16(nsDependentCString(stringToUse, inLength), utf16);
if (NS_FAILED(rv))
@ -820,7 +829,7 @@ int ConvertToUTF8(const char *stringToUse, int32_t inLength,
return 0;
}
auto encoding = mozilla::Encoding::ForLabel(nsDependentCString(input_charset));
auto encoding = mozilla::Encoding::ForLabel(newCharset);
if (!encoding) {
// Assume input is UTF-8.
encoding = UTF_8_ENCODING;