mirror of
https://github.com/moparisthebest/k-9
synced 2025-01-30 23:00:09 -05:00
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:
parent
92e9e6d140
commit
f89544ea8b
@ -391,7 +391,7 @@ public class HtmlConverter {
|
|||||||
* @param text Plain text to be linkified.
|
* @param text Plain text to be linkified.
|
||||||
* @param outputBuffer Buffer to append linked text to.
|
* @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>");
|
String prepared = text.replaceAll(Regex.BITCOIN_URI_PATTERN, "<a href=\"$0\">$0</a>");
|
||||||
|
|
||||||
Matcher m = Regex.WEB_URL_PATTERN.matcher(prepared);
|
Matcher m = Regex.WEB_URL_PATTERN.matcher(prepared);
|
||||||
|
@ -167,4 +167,18 @@ public class HtmlConverterTest extends TestCase {
|
|||||||
+ "</blockquote>"
|
+ "</blockquote>"
|
||||||
+ "</pre>", result);
|
+ "</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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user