Fixed explosion of generated autolink text

pull/147/head
Roland Illig 7 years ago
parent 62ac999d1a
commit 6952009782

@ -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("<a href=\"%s\">%s</a>", ref, ref));
matcher.appendReplacement(sb, String.format("<a href=\"%s\">%s</a>", ref, ref));
}
return text;
matcher.appendTail(sb);
return sb.toString();
}
static Drawable decodeImage(String source, Context context, long id, boolean show) {

@ -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.
"" +
"<a href=\"http://example.org/\">http://example.org/</a> and " +
"<a href=\"http://example.org/\">http://example.org/</a>subdir/"
"<a href=\"http://example.org/subdir/\">http://example.org/subdir/</a>"
);
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.
"" +
"<a href=\"" +
"<a href=\"" +
"<a href=\"http://example.org/\">http://example.org/</a>" +
"\">" +
"<a href=\"http://example.org/\">http://example.org/</a>" +
"</a>" +
"\">" +
"<a href=\"" +
"<a href=\"http://example.org/\">http://example.org/</a>" +
"\">" +
"<a href=\"http://example.org/\">http://example.org/</a>" +
"</a>" +
"</a>" +
" and " +
"<a href=\"" +
"<a href=\"" +
"<a href=\"http://example.org/\">http://example.org/</a>" +
"\">" +
"<a href=\"http://example.org/\">http://example.org/</a>" +
"</a>" +
"\">" +
"<a href=\"" +
"<a href=\"http://example.org/\">http://example.org/</a>" +
"\">" +
"<a href=\"http://example.org/\">http://example.org/</a>" +
"</a>" +
"</a>" +
" and " +
"<a href=\"" +
"<a href=\"" +
"<a href=\"http://example.org/\">http://example.org/</a>" +
"\">" +
"<a href=\"http://example.org/\">http://example.org/</a>" +
"</a>" +
"\">" +
"<a href=\"" +
"<a href=\"http://example.org/\">http://example.org/</a>" +
"\">" +
"<a href=\"http://example.org/\">http://example.org/</a>" +
"</a>" +
"</a>"
"<a href=\"http://example.org/\">http://example.org/</a>"
);
}

Loading…
Cancel
Save