diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java
index c51c03b8bf..f07e6e9fd3 100644
--- a/app/src/main/java/eu/faircode/email/HtmlHelper.java
+++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java
@@ -127,15 +127,22 @@ public class HtmlHelper {
static String autolink(String text) {
Matcher matcher = pattern.matcher(text);
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
+ int end = 0;
while (matcher.find()) {
- String ref = matcher.group();
- matcher.appendReplacement(sb, String.format("%s", ref, ref));
+ sb.append(html(text.substring(end, matcher.start())));
+ String ref = html(matcher.group());
+ sb.append(String.format("%s", ref, ref));
+ end = matcher.end();
}
- matcher.appendTail(sb);
+ sb.append(text.substring(end));
return sb.toString();
}
+ private static String html(String plain) {
+ return plain.replace("&", "&").replace("<", "<");
+ }
+
static Drawable decodeImage(String source, Context context, long id, boolean show) {
int px = Helper.dp2pixels(context, 48);
diff --git a/app/src/test/java/eu/faircode/email/HtmlHelperTest.java b/app/src/test/java/eu/faircode/email/HtmlHelperTest.java
index 4e91540515..9ca5787e46 100644
--- a/app/src/test/java/eu/faircode/email/HtmlHelperTest.java
+++ b/app/src/test/java/eu/faircode/email/HtmlHelperTest.java
@@ -28,10 +28,10 @@ class HtmlHelperTest {
testAutolink(
"https://example.org/search?q=%C3%A4&hl=nl",
- // TODO: Strictly speaking, the & should be encoded as &.
- // Most browsers can deal with this situation though.
- "" +
- "https://example.org/search?q=%C3%A4&hl=nl"
+ // The & should be encoded as &, even though
+ // most browsers can deal with this situation.
+ "" +
+ "https://example.org/search?q=%C3%A4&hl=nl"
);
testAutolink(
@@ -43,8 +43,8 @@ class HtmlHelperTest {
testAutolink(
"Go to .",
- // FIXME: The < must be encoded as <.
- "Go to <http://example.org/>."
+ // The < must be encoded as <, to avoid confusion.
+ "Go to <http://example.org/>."
);
testAutolink(