From 5986051d9dcb920217ec97a1a9a3f87bd908ff7e Mon Sep 17 00:00:00 2001 From: Roland Illig Date: Sat, 16 Feb 2019 22:42:44 +0100 Subject: [PATCH] Properly autolink URLs with unescaped parentheses --- app/src/main/java/eu/faircode/email/HtmlHelper.java | 10 ++++++++-- .../test/java/eu/faircode/email/HtmlHelperTest.java | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index 413383d1b9..8f301f30f9 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -131,9 +131,15 @@ public class HtmlHelper { int end = 0; while (matcher.find()) { sb.append(Html.escapeHtml(text.substring(end, matcher.start()))); - String ref = Html.escapeHtml(matcher.group()); + + String url = matcher.group(); + if (url.endsWith(")") && !url.contains("(")) { + url = url.substring(0, url.length() - 1); + } + + String ref = Html.escapeHtml(url); sb.append(String.format("%s", ref, ref)); - end = matcher.end(); + end = matcher.start() + url.length(); } sb.append(text.substring(end)); return sb.toString(); diff --git a/app/src/test/java/eu/faircode/email/HtmlHelperTest.java b/app/src/test/java/eu/faircode/email/HtmlHelperTest.java index 9e452a6006..4438bb66fc 100644 --- a/app/src/test/java/eu/faircode/email/HtmlHelperTest.java +++ b/app/src/test/java/eu/faircode/email/HtmlHelperTest.java @@ -120,10 +120,10 @@ public class HtmlHelperTest { testAutolink( "See my homepage (at https://example.org), with lots of examples.", - // FIXME: The URL doesn't contain an opening parenthesis, therefore + // This URL doesn't contain an opening parenthesis, therefore // the closing parenthesis probably also doesn't belong to it. - "See my homepage (at " + - "https://example.org), with lots of examples." + "See my homepage (at " + + "https://example.org), with lots of examples." ); // The terminating sequence of a base64-encoded URL parameter is always