diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java
index cc7f533974..7d436bb3f0 100644
--- a/app/src/main/java/eu/faircode/email/HtmlHelper.java
+++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java
@@ -127,11 +127,13 @@ public class HtmlHelper {
static String autolink(String text) {
Matcher matcher = pattern.matcher(text);
+ StringBuffer sb = new StringBuffer();
while (matcher.find()) {
String ref = matcher.group();
- text = text.replace(ref, String.format("%s", ref, ref));
+ matcher.appendReplacement(sb, String.format("%s", ref, ref));
}
- return text;
+ matcher.appendTail(sb);
+ return sb.toString();
}
static Drawable decodeImage(String source, Context context, long id, boolean show) {
diff --git a/app/src/test/java/eu/faircode/email/HtmlHelperTest.java b/app/src/test/java/eu/faircode/email/HtmlHelperTest.java
index 172fd181bd..21f804b400 100644
--- a/app/src/test/java/eu/faircode/email/HtmlHelperTest.java
+++ b/app/src/test/java/eu/faircode/email/HtmlHelperTest.java
@@ -50,59 +50,23 @@ class HtmlHelperTest {
testAutolink(
"http://example.org/ and http://example.org/subdir/",
- // FIXME: Each URL must be linked to its exact address, not just to a prefix.
+ // Each URL must be linked to its exact address, not just to a prefix.
"" +
"http://example.org/ and " +
- "http://example.org/subdir/"
+ "http://example.org/subdir/"
);
testAutolink(
"http://example.org/ and http://example.org/ and http://example.org/",
- // FIXME: Even when the same URL is mentioned multiple times,
+ // When the same URL is mentioned multiple times,
// each of the URLs must only appear a single time.
"" +
- "http://example.org/" +
- "\">" +
- "http://example.org/" +
- "" +
- "\">" +
- "http://example.org/" +
- "\">" +
- "http://example.org/" +
- "" +
- "" +
" and " +
- "http://example.org/" +
- "\">" +
- "http://example.org/" +
- "" +
- "\">" +
- "http://example.org/" +
- "\">" +
- "http://example.org/" +
- "" +
- "" +
" and " +
- "http://example.org/" +
- "\">" +
- "http://example.org/" +
- "" +
- "\">" +
- "http://example.org/" +
- "\">" +
- "http://example.org/" +
- "" +
- ""
+ "http://example.org/"
);
}