Fixed html charset edge case

This commit is contained in:
M66B 2021-06-17 13:48:49 +02:00
parent fe22ed2a8b
commit 63114d05f0
2 changed files with 7 additions and 6 deletions

View File

@ -146,10 +146,7 @@ public class text_plain extends handler_base {
String charset = ct.getParameter("charset");
if (charset == null)
// If the charset parameter is absent, use US-ASCII.
charset = "us-ascii";
if ("us-ascii".equals(charset) &&
"text/html".equalsIgnoreCase(ct.getBaseType()))
charset = StandardCharsets.UTF_8.name();
charset = StandardCharsets.ISO_8859_1.name();
return MimeUtility.javaCharset(charset);
} catch (Exception ex) {
return null;

View File

@ -1907,8 +1907,11 @@ public class MessageHelper {
result = HtmlHelper.flow(result);
result = "<div x-plain=\"true\">" + HtmlHelper.formatPre(result) + "</div>";
} else if (h.isHtml()) {
// Fix incorrect UTF16
if (charset != null)
if (charset == null) {
if (CharsetHelper.isUTF8(result))
result = new String(result.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
} else {
// Fix incorrect UTF16
try {
Charset c = Charset.forName(charset);
if (CHARSET16.contains(c)) {
@ -1924,6 +1927,7 @@ public class MessageHelper {
} catch (Throwable ex) {
Log.w(ex);
}
}
if (charset == null) {
// <meta charset="utf-8" />