From f586a5dfdfb736644e10453ab54afa52dc19e3e0 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sun, 25 Jun 2023 22:32:26 -0500 Subject: [PATCH] Fix using bookmarks with advanced nicks --- .../eu/siacs/conversations/entities/Bookmark.java | 15 +++++++++++++-- .../siacs/conversations/entities/MucOptions.java | 6 +++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Bookmark.java b/src/main/java/eu/siacs/conversations/entities/Bookmark.java index 2f3b4badf..0de0dc9da 100644 --- a/src/main/java/eu/siacs/conversations/entities/Bookmark.java +++ b/src/main/java/eu/siacs/conversations/entities/Bookmark.java @@ -192,8 +192,19 @@ public class Bookmark extends Element implements ListItem { } public Jid getFullJid() { - final String nick = getNick(); - return jid == null || nick == null || nick.trim().isEmpty() ? jid : jid.withResource(nick); + return getFullJid(getNick(), true); + } + + private Jid getFullJid(final String nick, boolean tryFix) { + try { + return jid == null || nick == null || nick.trim().isEmpty() ? jid : jid.withResource(nick); + } catch (final IllegalArgumentException e) { + try { + return tryFix ? getFullJid(gnu.inet.encoding.Punycode.encode(nick), false) : null; + } catch (final gnu.inet.encoding.PunycodeException e2) { + return null; + } + } } public List getGroupTags() { diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java index 954d65dca..3336f72f2 100644 --- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java +++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java @@ -110,7 +110,7 @@ public class MucOptions { void notifyOfBookmarkNick(final String nick) { final String normalized = normalize(account.getJid(),nick); - if (normalized != null && normalized.equals(getSelf().getFullJid().getResource())) { + if (normalized != null && normalized.equals(getSelf().getNick())) { this.tookProposedNickFromBookmark = true; } } @@ -469,12 +469,12 @@ public class MucOptions { if (account == null || TextUtils.isEmpty(nick)) { return null; } + try { return account.withResource(nick).getResource(); } catch (IllegalArgumentException e) { - return null; + return nick; } - } public String getActualNick() { -- 2.45.2