diff --git a/utf8.c b/utf8.c index a544f15456..e7caef4721 100644 --- a/utf8.c +++ b/utf8.c @@ -480,9 +480,25 @@ char *reencode_string(const char *in, const char *out_encoding, const char *in_e if (!in_encoding) return NULL; + conv = iconv_open(out_encoding, in_encoding); - if (conv == (iconv_t) -1) - return NULL; + if (conv == (iconv_t) -1) { + /* + * Some platforms do not have the variously spelled variants of + * UTF-8, so let's fall back to trying the most official + * spelling. We do so only as a fallback in case the platform + * does understand the user's spelling, but not our official + * one. + */ + if (is_encoding_utf8(in_encoding)) + in_encoding = "UTF-8"; + if (is_encoding_utf8(out_encoding)) + out_encoding = "UTF-8"; + conv = iconv_open(out_encoding, in_encoding); + if (conv == (iconv_t) -1) + return NULL; + } + out = reencode_string_iconv(in, strlen(in), conv); iconv_close(conv); return out;