stop parsing random strings as xmpp addresses when scanning uris

This commit is contained in:
Daniel Gultsch 2020-12-02 08:19:06 +01:00
parent 778cfa846b
commit 528f192f76
2 changed files with 4 additions and 6 deletions

View File

@ -21,6 +21,8 @@ import android.widget.AdapterView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import com.google.common.base.Strings;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -347,7 +349,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity im
private void handleActivityResult(ActivityResult activityResult) { private void handleActivityResult(ActivityResult activityResult) {
if (activityResult.resultCode == RESULT_OK && activityResult.requestCode == ScanActivity.REQUEST_SCAN_QR_CODE) { if (activityResult.resultCode == RESULT_OK && activityResult.requestCode == ScanActivity.REQUEST_SCAN_QR_CODE) {
String result = activityResult.data.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT); String result = activityResult.data.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
XmppUri uri = new XmppUri(result == null ? "" : result); XmppUri uri = new XmppUri(Strings.nullToEmpty(result));
if (uri.isValidJid()) { if (uri.isValidJid()) {
showEnterJidDialog(uri); showEnterJidDialog(uri);
} }

View File

@ -174,13 +174,9 @@ public class XmppUri {
jid = null; jid = null;
} }
} else { } else {
try {
jid = Jid.ofEscaped(uri.toString()).asBareJid().toEscapedString();
} catch (final IllegalArgumentException ignored) {
jid = null; jid = null;
} }
} }
}
@Override @Override
@NonNull @NonNull