Add failing test for HtmlConverter.linkifyText()

There's currently a bug in linkifyText() that can lead to a
StringIndexOutOfBoundsException when the text contains a
bitcoin URI and a "web" URI near the end of the text.
This commit is contained in:
cketti 2014-02-17 18:19:52 +01:00
parent 92e9e6d140
commit f89544ea8b
2 changed files with 15 additions and 1 deletions

View File

@ -391,7 +391,7 @@ public class HtmlConverter {
* @param text Plain text to be linkified.
* @param outputBuffer Buffer to append linked text to.
*/
private static void linkifyText(final String text, final StringBuffer outputBuffer) {
protected static void linkifyText(final String text, final StringBuffer outputBuffer) {
String prepared = text.replaceAll(Regex.BITCOIN_URI_PATTERN, "<a href=\"$0\">$0</a>");
Matcher m = Regex.WEB_URL_PATTERN.matcher(prepared);

View File

@ -167,4 +167,18 @@ public class HtmlConverterTest extends TestCase {
+ "</blockquote>"
+ "</pre>", result);
}
public void testLinkifyBitcoinAndHttpUri() {
String text = "bitcoin:19W6QZkx8SYPG7BBCS7odmWGRxqRph5jFU http://example.com/";
StringBuffer outputBuffer = new StringBuffer();
HtmlConverter.linkifyText(text, outputBuffer);
assertEquals("<a href=\"bitcoin:19W6QZkx8SYPG7BBCS7odmWGRxqRph5jFU\">" +
"bitcoin:19W6QZkx8SYPG7BBCS7odmWGRxqRph5jFU" +
"</a> " +
"<a href=\"http://example.com/\">" +
"http://example.com/" +
"</a>", outputBuffer.toString());
}
}