From c58c0ad34778588f1631ea409b507c3725f2d4c9 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Sat, 7 Apr 2018 23:36:33 +0200 Subject: fixed some issues with jid escaping --- .../pixart/messenger/ui/MagicCreateActivity.java | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/main/java/de/pixart') diff --git a/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java b/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java index 91c527ca1..8c758be6d 100644 --- a/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java +++ b/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java @@ -58,14 +58,14 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher { mRandom = new SecureRandom(); Button next = findViewById(R.id.create_account); next.setOnClickListener(v -> { - String username = mUsername.getText().toString(); - if (username.contains("@") || username.length() < 3) { - mUsername.setError(getString(R.string.invalid_username)); - mUsername.requestFocus(); - } else { - mUsername.setError(null); - try { - Jid jid = Jid.of(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); + try { + String username = mUsername.getText().toString(); + 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.requestFocus(); + } else { + mUsername.setError(null); Account account = xmppConnectionService.findAccountByJid(jid); if (account == null) { account = new Account(jid, createPassword()); @@ -81,10 +81,10 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher { Toast.makeText(MagicCreateActivity.this, R.string.secure_password_generated, Toast.LENGTH_SHORT).show(); WelcomeActivity.addInviteUri(intent, getIntent()); startActivity(intent); - } catch (IllegalArgumentException e) { - mUsername.setError(getString(R.string.invalid_username)); - mUsername.requestFocus(); } + } catch (IllegalArgumentException e) { + mUsername.setError(getString(R.string.invalid_username)); + mUsername.requestFocus(); } }); mUsername.addTextChangedListener(this); @@ -114,7 +114,7 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher { try { mFullJidDisplay.setVisibility(View.VISIBLE); 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) { mFullJidDisplay.setVisibility(View.INVISIBLE); } -- cgit v1.2.3