Do not crash when XMPP URI contains invalid JID

This commit is contained in:
Stephen Paul Weber 2022-03-10 13:24:18 -05:00
parent bb1e1a8b24
commit e6a5b4288e

View file

@ -501,12 +501,14 @@ public class MessageAdapter extends ArrayAdapter<Message> {
for (final URLSpan urlspan : body.getSpans(0, body.length() - 1, URLSpan.class)) { for (final URLSpan urlspan : body.getSpans(0, body.length() - 1, URLSpan.class)) {
Uri uri = Uri.parse(urlspan.getURL()); Uri uri = Uri.parse(urlspan.getURL());
if ("xmpp".equals(uri.getScheme())) { if ("xmpp".equals(uri.getScheme())) {
Contact contact = roster.getContact(Jid.of(uri.getSchemeSpecificPart())); try {
body.replace( Contact contact = roster.getContact(Jid.of(uri.getSchemeSpecificPart()));
body.getSpanStart(urlspan), body.replace(
body.getSpanEnd(urlspan), body.getSpanStart(urlspan),
contact.getDisplayName() body.getSpanEnd(urlspan),
); contact.getDisplayName()
);
} catch (final IllegalArgumentException e) { /* bad JID */ }
} }
} }
viewHolder.messageBody.setAutoLinkMask(0); viewHolder.messageBody.setAutoLinkMask(0);