fixed some issues with jid escaping

This commit is contained in:
Daniel Gultsch 2018-03-11 18:32:16 +01:00
parent b2a9c63568
commit 72388e37f5
4 changed files with 15 additions and 16 deletions

View file

@ -58,14 +58,14 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
mRandom = new SecureRandom(); mRandom = new SecureRandom();
Button next = findViewById(R.id.create_account); Button next = findViewById(R.id.create_account);
next.setOnClickListener(v -> { next.setOnClickListener(v -> {
try {
String username = mUsername.getText().toString(); String username = mUsername.getText().toString();
if (username.contains("@") || username.length() < 3) { Jid jid = Jid.of(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null);
if (!jid.getEscapedLocal().equals(jid.getLocal())|| username.length() < 3) {
mUsername.setError(getString(R.string.invalid_username)); mUsername.setError(getString(R.string.invalid_username));
mUsername.requestFocus(); mUsername.requestFocus();
} else { } else {
mUsername.setError(null); mUsername.setError(null);
try {
Jid jid = Jid.of(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null);
Account account = xmppConnectionService.findAccountByJid(jid); Account account = xmppConnectionService.findAccountByJid(jid);
if (account == null) { if (account == null) {
account = new Account(jid, createPassword()); account = new Account(jid, createPassword());
@ -81,11 +81,11 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
Toast.makeText(MagicCreateActivity.this, R.string.secure_password_generated, Toast.LENGTH_SHORT).show(); Toast.makeText(MagicCreateActivity.this, R.string.secure_password_generated, Toast.LENGTH_SHORT).show();
WelcomeActivity.addInviteUri(intent, getIntent()); WelcomeActivity.addInviteUri(intent, getIntent());
startActivity(intent); startActivity(intent);
}
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
mUsername.setError(getString(R.string.invalid_username)); mUsername.setError(getString(R.string.invalid_username));
mUsername.requestFocus(); mUsername.requestFocus();
} }
}
}); });
mUsername.addTextChangedListener(this); mUsername.addTextChangedListener(this);
} }
@ -114,7 +114,7 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher {
try { try {
mFullJidDisplay.setVisibility(View.VISIBLE); mFullJidDisplay.setVisibility(View.VISIBLE);
Jid jid = Jid.of(s.toString().toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); Jid jid = Jid.of(s.toString().toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null);
mFullJidDisplay.setText(getString(R.string.your_full_jid_will_be, jid.toString())); mFullJidDisplay.setText(getString(R.string.your_full_jid_will_be, jid.toEscapedString()));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
mFullJidDisplay.setVisibility(View.INVISIBLE); mFullJidDisplay.setVisibility(View.INVISIBLE);
} }

View file

@ -369,7 +369,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
Bookmark bookmark = (Bookmark) conferences.get(position); Bookmark bookmark = (Bookmark) conferences.get(position);
Intent shareIntent = new Intent(); Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, "xmpp:" + bookmark.getJid().asBareJid().toString() + "?join"); shareIntent.putExtra(Intent.EXTRA_TEXT, "xmpp:" + bookmark.getJid().asBareJid().toEscapedString() + "?join");
shareIntent.setType("text/plain"); shareIntent.setType("text/plain");
try { try {
startActivity(Intent.createChooser(shareIntent, getText(R.string.share_uri_with))); startActivity(Intent.createChooser(shareIntent, getText(R.string.share_uri_with)));

View file

@ -151,9 +151,8 @@ public class Element {
final String jid = this.getAttribute(name); final String jid = this.getAttribute(name);
if (jid != null && !jid.isEmpty()) { if (jid != null && !jid.isEmpty()) {
try { try {
return Jid.of(jid); return Jid.ofEscaped(jid);
} catch (final IllegalArgumentException e) { } catch (final IllegalArgumentException e) {
Log.e(Config.LOGTAG, "could not parse jid " + jid);
return null; return null;
} }
} }

View file

@ -1020,7 +1020,7 @@ public class XmppConnection implements Runnable {
final Element jid = bind.findChild("jid"); final Element jid = bind.findChild("jid");
if (jid != null && jid.getContent() != null) { if (jid != null && jid.getContent() != null) {
try { try {
Jid assignedJid = Jid.of(jid.getContent()); Jid assignedJid = Jid.ofEscaped(jid.getContent());
if (!account.getJid().getDomain().equals(assignedJid.getDomain())) { if (!account.getJid().getDomain().equals(assignedJid.getDomain())) {
Log.d(Config.LOGTAG,account.getJid().asBareJid()+": server tried to re-assign domain to "+assignedJid.getDomain()); Log.d(Config.LOGTAG,account.getJid().asBareJid()+": server tried to re-assign domain to "+assignedJid.getDomain());
throw new StateChangingError(Account.State.BIND_FAILURE); throw new StateChangingError(Account.State.BIND_FAILURE);