@Test public void testLinkifyUrls__parentheses() { String input = "Hi, please check my website! (www.google.com)"; String expected = "Hi, please check my website! (<a rel='nofollow' href='http: String message = "Parentheses are not handled correctly in linkification."; assertEquals(message, expected, HtmlUtil.linkifyUrlsInHtml(input)); }
public static String linkifyUrlsInHtml(String content) { Matcher existingLinksMatcher = existingLinksPattern.matcher(content); StringBuilder result = new StringBuilder(); int lastIndex = 0; while (existingLinksMatcher.find()) { int startIndex = existingLinksMatcher.start(); int endIndex = existingLinksMatcher.end(); String beforeText = content.substring(lastIndex, startIndex); result.append(linkifyUrlsInText(beforeText)); String existingLink = content.substring(startIndex, endIndex); result.append(existingLink); lastIndex = endIndex; } String afterText = content.substring(lastIndex, content.length()); result.append(linkifyUrlsInText(afterText)); return result.toString(); }
HtmlUtil { public static String linkifyUrlsInHtml(String content) { Matcher existingLinksMatcher = existingLinksPattern.matcher(content); StringBuilder result = new StringBuilder(); int lastIndex = 0; while (existingLinksMatcher.find()) { int startIndex = existingLinksMatcher.start(); int endIndex = existingLinksMatcher.end(); String beforeText = content.substring(lastIndex, startIndex); result.append(linkifyUrlsInText(beforeText)); String existingLink = content.substring(startIndex, endIndex); result.append(existingLink); lastIndex = endIndex; } String afterText = content.substring(lastIndex, content.length()); result.append(linkifyUrlsInText(afterText)); return result.toString(); } }
HtmlUtil { public static String linkifyUrlsInHtml(String content) { Matcher existingLinksMatcher = existingLinksPattern.matcher(content); StringBuilder result = new StringBuilder(); int lastIndex = 0; while (existingLinksMatcher.find()) { int startIndex = existingLinksMatcher.start(); int endIndex = existingLinksMatcher.end(); String beforeText = content.substring(lastIndex, startIndex); result.append(linkifyUrlsInText(beforeText)); String existingLink = content.substring(startIndex, endIndex); result.append(existingLink); lastIndex = endIndex; } String afterText = content.substring(lastIndex, content.length()); result.append(linkifyUrlsInText(afterText)); return result.toString(); } private  HtmlUtil(); }
HtmlUtil { public static String linkifyUrlsInHtml(String content) { Matcher existingLinksMatcher = existingLinksPattern.matcher(content); StringBuilder result = new StringBuilder(); int lastIndex = 0; while (existingLinksMatcher.find()) { int startIndex = existingLinksMatcher.start(); int endIndex = existingLinksMatcher.end(); String beforeText = content.substring(lastIndex, startIndex); result.append(linkifyUrlsInText(beforeText)); String existingLink = content.substring(startIndex, endIndex); result.append(existingLink); lastIndex = endIndex; } String afterText = content.substring(lastIndex, content.length()); result.append(linkifyUrlsInText(afterText)); return result.toString(); } private  HtmlUtil(); static String cleanAll(String text); static String cleanMost(String text); static String cleanSome(String text, String baseUri); static String clean(String text, Whitelist whitelist, String baseUri); static String decodeHTMLEntitiesForEmail(String body); static String linkifyUrlsInText(String content); static String linkifyUrlsInHtml(String content); static String makeRelativeLinksAbsolute(String html, String baseUrl); static String createLink(String url, String desc); static String addHtmlLineBreaks(String content); static String filterAndFormatContent(String content); static Document addNoFollowToLinkTagsInDocument(Document document); }
HtmlUtil { public static String linkifyUrlsInHtml(String content) { Matcher existingLinksMatcher = existingLinksPattern.matcher(content); StringBuilder result = new StringBuilder(); int lastIndex = 0; while (existingLinksMatcher.find()) { int startIndex = existingLinksMatcher.start(); int endIndex = existingLinksMatcher.end(); String beforeText = content.substring(lastIndex, startIndex); result.append(linkifyUrlsInText(beforeText)); String existingLink = content.substring(startIndex, endIndex); result.append(existingLink); lastIndex = endIndex; } String afterText = content.substring(lastIndex, content.length()); result.append(linkifyUrlsInText(afterText)); return result.toString(); } private  HtmlUtil(); static String cleanAll(String text); static String cleanMost(String text); static String cleanSome(String text, String baseUri); static String clean(String text, Whitelist whitelist, String baseUri); static String decodeHTMLEntitiesForEmail(String body); static String linkifyUrlsInText(String content); static String linkifyUrlsInHtml(String content); static String makeRelativeLinksAbsolute(String html, String baseUrl); static String createLink(String url, String desc); static String addHtmlLineBreaks(String content); static String filterAndFormatContent(String content); static Document addNoFollowToLinkTagsInDocument(Document document);  }