mirror of
https://github.com/igniterealtime/Spark.git
synced 2026-08-18 02:56:24 +00:00
Fix contact JID handling and roster fallback
This commit is contained in:
committed by
Sergey Ponomarev
parent
9f994c019e
commit
7b1d20f204
@ -280,6 +280,9 @@ public class UserManager {
|
||||
}
|
||||
|
||||
String node = XmppStringUtils.parseLocalpart(jid);
|
||||
if (node == null || node.isEmpty()) {
|
||||
return jid;
|
||||
}
|
||||
String restOfJID = jid.substring(node.length());
|
||||
String builder = XmppStringUtils.escapeLocalpart(node) + restOfJID;
|
||||
return builder;
|
||||
|
||||
@ -540,11 +540,12 @@ public class RosterDialog implements ActionListener {
|
||||
if (roster.isSubscriptionPreApprovalSupported()) {
|
||||
try {
|
||||
roster.preApproveAndCreateEntry(contactJid, displayName, parentNames);
|
||||
} catch (SmackException.FeatureNotSupportedException ignored) {
|
||||
return;
|
||||
} catch (SmackException.FeatureNotSupportedException e) {
|
||||
Log.debug("Roster subscription pre-approval is unavailable; using a regular subscription request.");
|
||||
}
|
||||
} else {
|
||||
roster.createItemAndRequestSubscription(contactJid, displayName, parentNames);
|
||||
}
|
||||
roster.createItemAndRequestSubscription(contactJid, displayName, parentNames);
|
||||
}
|
||||
|
||||
public List<AccountItem> getAccounts() {
|
||||
@ -571,7 +572,7 @@ public class RosterDialog implements ActionListener {
|
||||
return;
|
||||
}
|
||||
|
||||
String contact = UserManager.escapeJID(jid);
|
||||
String contact = jid;
|
||||
String nickname = nicknameField.getText();
|
||||
String group = (String) groupBox.getSelectedItem();
|
||||
|
||||
@ -592,6 +593,10 @@ public class RosterDialog implements ActionListener {
|
||||
}
|
||||
}
|
||||
|
||||
// Escape only after a complete JID has been constructed. Escaping a bare
|
||||
// username first causes XmppStringUtils.parseLocalpart() to return null.
|
||||
contact = UserManager.escapeJID(contact);
|
||||
|
||||
if (!ModelUtil.hasLength(nickname) && ModelUtil.hasLength(contact)) {
|
||||
// Try to load nickname from VCard
|
||||
try {
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
package org.jivesoftware.spark;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class UserManagerTest {
|
||||
|
||||
@Test
|
||||
public void escapeJidKeepsUsernameWithoutDomain() {
|
||||
assertEquals("alice", UserManager.escapeJID("alice"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void escapeJidEscapesCompleteJidLocalpart() {
|
||||
assertEquals("alice\\20smith@example.org", UserManager.escapeJID("alice smith@example.org"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void escapeJidKeepsNull() {
|
||||
assertNull(UserManager.escapeJID(null));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user