Improved autolink feature

pull/147/head
Roland Illig 7 years ago
parent de5e571e71
commit cf894b3726

@ -60,7 +60,7 @@ import static androidx.core.text.HtmlCompat.TO_HTML_PARAGRAPH_LINES_CONSECUTIVE;
public class HtmlHelper { public class HtmlHelper {
private static final int PREVIEW_SIZE = 250; private static final int PREVIEW_SIZE = 250;
private static Pattern pattern = Pattern.compile("([http|https]+://[\\w\\S(\\.|:|/)]+)"); private static Pattern pattern = Pattern.compile("https?://[\\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> 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"); private static final List<String> tails = Arrays.asList("h1", "h2", "h3", "h4", "h5", "h6", "p", "ol", "ul", "li");

@ -21,8 +21,8 @@ class HtmlHelperTest {
testAutolink( testAutolink(
"one hhhhh|spt://example.org three", "one hhhhh|spt://example.org three",
// FIXME: "hhhhh|spt" is not a proper URL scheme. // This string had been wrongly interpreted as a complete URL up to February 2019.
"one <a href=\"hhhhh|spt://example.org\">hhhhh|spt://example.org</a> three" "one hhhhh|spt://example.org three"
); );
testAutolink( testAutolink(
@ -37,16 +37,14 @@ class HtmlHelperTest {
testAutolink( testAutolink(
"Go to \"http://example.org/\".", "Go to \"http://example.org/\".",
// FIXME: The quote must not end up as part of the URL. "Go to \"<a href=\"http://example.org/\">http://example.org/</a>\"."
"Go to \"<a href=\"http://example.org/\".\">http://example.org/\".</a>"
); );
testAutolink( testAutolink(
"Go to <http://example.org/>.", "Go to <http://example.org/>.",
// FIXME: The < must be encoded as &lt;. // FIXME: The < must be encoded as &lt;.
// FIXME: THe > must not end up as part of the URL. "Go to <<a href=\"http://example.org/\">http://example.org/</a>>."
"Go to <<a href=\"http://example.org/>.\">http://example.org/>.</a>"
); );
} }

Loading…
Cancel
Save