Fixed autolink of URLs followed by punctuation

pull/147/head
Roland Illig 7 years ago
parent 6952009782
commit 0b3fde5ee3

@ -60,7 +60,7 @@ import static androidx.core.text.HtmlCompat.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE;
public class HtmlHelper {
private static final int PREVIEW_SIZE = 250;
private static Pattern pattern = Pattern.compile("https?://[\\w#%&()*+,-./:;=?@\\[\\]_|~]+");
private static final Pattern pattern = Pattern.compile("https?://[\\w#%&()*+,\\-./:;=?@\\[\\]_|~]*[\\w#)*+\\-/=@\\]|~]");
private static final List<String> heads = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6", "p", "table", "ol", "ul", "br", "hr");
private static final List<String> tails = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6", "p", "ol", "ul", "li");

@ -13,10 +13,10 @@ class HtmlHelperTest {
"To visit http://www.example.org, go to http://www.example.org.",
"" +
// FIXME: The trailing comma must not be part of the URL.
"To visit <a href=\"http://www.example.org,\">http://www.example.org,</a> " +
// FIXME: The trailing dot must not be part of the URL.
"go to <a href=\"http://www.example.org.\">http://www.example.org.</a>");
// The trailing comma must not be part of the URL.
"To visit <a href=\"http://www.example.org\">http://www.example.org</a>, " +
// The trailing dot must not be part of the URL.
"go to <a href=\"http://www.example.org\">http://www.example.org</a>.");
testAutolink(
"one hhhhh|spt://example.org three",

Loading…
Cancel
Save