From effeb7b585054c89d993e5fc7e42deebfb3ca325 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 28 Apr 2018 21:30:30 +0200 Subject: [PATCH] convert empty resources in messages to bare jid --- src/main/java/eu/siacs/conversations/xml/Element.java | 3 ++- .../java/eu/siacs/conversations/xmpp/InvalidJid.java | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/xml/Element.java b/src/main/java/eu/siacs/conversations/xml/Element.java index b103e8647..b31cef68e 100644 --- a/src/main/java/eu/siacs/conversations/xml/Element.java +++ b/src/main/java/eu/siacs/conversations/xml/Element.java @@ -12,6 +12,7 @@ import java.util.Locale; import eu.siacs.conversations.Config; import eu.siacs.conversations.utils.XmlHelper; import eu.siacs.conversations.xmpp.InvalidJid; +import eu.siacs.conversations.xmpp.stanzas.MessagePacket; import rocks.xmpp.addr.Jid; public class Element { @@ -154,7 +155,7 @@ public class Element { try { return Jid.ofEscaped(jid); } catch (final IllegalArgumentException e) { - return new InvalidJid(jid); + return InvalidJid.of(jid, this instanceof MessagePacket); } } return null; diff --git a/src/main/java/eu/siacs/conversations/xmpp/InvalidJid.java b/src/main/java/eu/siacs/conversations/xmpp/InvalidJid.java index e1f257fd3..66f6bfb90 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/InvalidJid.java +++ b/src/main/java/eu/siacs/conversations/xmpp/InvalidJid.java @@ -37,9 +37,18 @@ public class InvalidJid implements Jid { private final String value; - public InvalidJid(String jid) { + private InvalidJid(String jid) { this.value = jid; } + public static Jid of(String jid, boolean fallback) { + final int pos = jid.indexOf('/'); + if (fallback && pos >= 0 && jid.length() >= pos + 1) { + if (jid.substring(pos+1).trim().isEmpty()) { + return Jid.ofEscaped(jid.substring(0,pos)); + } + } + return new InvalidJid(jid); + } @Override @NonNull