Fixed html charset edge case

pull/199/head
M66B 4 years ago
parent fe22ed2a8b
commit 63114d05f0

@ -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;

@ -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" />

Loading…
Cancel
Save