Tighten body-tag auto-direction injection edge handling

Agent-Logs-Url: https://github.com/ArcaneChat/android/sessions/7f55ea69-ba6c-40ad-a72e-3080ac96b847

Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-05-08 13:12:30 +00:00
committed by GitHub
parent 02812b0f3b
commit cb84e9fe3c
@@ -151,7 +151,7 @@ public class FullMsgActivity extends WebViewActivity {
int bodyTagStart = lowercaseHtml.indexOf("<body");
if (bodyTagStart >= 0) {
int bodyTagEnd = lowercaseHtml.indexOf(">", bodyTagStart);
if (bodyTagEnd <= bodyTagStart) {
if (bodyTagEnd < 0) {
return html;
}
String bodyTag = html.substring(bodyTagStart, bodyTagEnd + 1);
@@ -159,9 +159,10 @@ public class FullMsgActivity extends WebViewActivity {
if (lowercaseBodyTag.contains("dir=")) {
return html;
}
String tagCloser = lowercaseBodyTag.endsWith("/>") ? "/>" : ">";
String updatedBodyTag =
bodyTag.substring(0, bodyTag.length() - tagCloser.length()) + " dir=\"auto\"" + tagCloser;
if (lowercaseBodyTag.endsWith("/>")) {
return html;
}
String updatedBodyTag = bodyTag.substring(0, bodyTag.length() - 1) + " dir=\"auto\">";
return html.substring(0, bodyTagStart) + updatedBodyTag + html.substring(bodyTagEnd + 1);
}
return "<div dir=\"auto\">" + html + "</div>";