encode and decode % and # in invite links

This commit is contained in:
Daniel Gultsch 2018-05-04 12:18:31 +02:00
parent 9b73029267
commit 77fc8d2d9e
4 changed files with 78 additions and 69 deletions

View file

@ -6,9 +6,6 @@ import android.os.SystemClock;
import android.util.Log;
import android.util.Pair;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.crypto.PgpDecryptionService;
import org.json.JSONException;
import org.json.JSONObject;
@ -19,7 +16,9 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.PgpDecryptionService;
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.crypto.axolotl.XmppAxolotlSession;
import eu.siacs.conversations.services.XmppConnectionService;
@ -629,7 +628,7 @@ public class Account extends AbstractEntity {
public String getShareableLink() {
List<XmppUri.Fingerprint> fingerprints = this.getFingerprints();
String uri = "https://conversations.im/i/"+this.getJid().asBareJid().toEscapedString();
String uri = "https://conversations.im/i/" + XmppUri.lameUrlEncode(this.getJid().asBareJid().toEscapedString());
if (fingerprints.size() > 0) {
return XmppUri.getFingerprintUri(uri, fingerprints, '&');
} else {

View file

@ -45,6 +45,7 @@ import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdat
import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate;
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.utils.XmppUri;
import rocks.xmpp.addr.Jid;
public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConfigurationPushed {
@ -298,7 +299,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
protected String getShareableUri(boolean http) {
if (mConversation != null) {
if (http) {
return "https://conversations.im/j/" + mConversation.getJid().asBareJid().toEscapedString();
return "https://conversations.im/j/" + XmppUri.lameUrlEncode(mConversation.getJid().asBareJid().toEscapedString());
} else {
return "xmpp:" + mConversation.getJid().asBareJid() + "?join";
}

View file

@ -10,7 +10,6 @@ import android.preference.PreferenceManager;
import android.provider.ContactsContract.CommonDataKinds;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Intents;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
@ -163,11 +162,10 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
@Override
protected String getShareableUri(boolean http) {
final String prefix = http ? "https://conversations.im/i/" : "xmpp:";
if (contact != null) {
return prefix+contact.getJid().asBareJid().toEscapedString();
if (http) {
return "https://conversations.im/j/" + XmppUri.lameUrlEncode(contact.getJid().asBareJid().toEscapedString());
} else {
return "";
return "xmpp:" + contact.getJid().asBareJid().toEscapedString();
}
}

View file

@ -1,6 +1,7 @@
package eu.siacs.conversations.utils;
import android.net.Uri;
import android.util.Log;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
@ -8,6 +9,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import eu.siacs.conversations.Config;
import rocks.xmpp.addr.Jid;
public class XmppUri {
@ -21,7 +23,6 @@ public class XmppUri {
protected boolean safeSource = true;
public static final String OMEMO_URI_PARAM = "omemo-sid-";
public static final String OTR_URI_PARAM = "otr-fingerprint";
public static final String ACTION_JOIN = "join";
public static final String ACTION_MESSAGE = "message";
@ -60,8 +61,9 @@ public class XmppUri {
if (segments.size() >= 2 && segments.get(1).contains("@")) {
// sample : https://conversations.im/i/foo@bar.com
try {
jid = Jid.of(segments.get(1)).toString();
jid = Jid.of(lameUrlDecode(segments.get(1))).toString();
} catch (Exception e) {
Log.d(Config.LOGTAG, "parsing failed ", e);
jid = null;
}
} else if (segments.size() >= 3) {
@ -211,6 +213,7 @@ public class XmppUri {
public boolean hasFingerprints() {
return fingerprints.size() > 0;
}
public enum FingerprintType {
OMEMO
}
@ -253,4 +256,12 @@ public class XmppUri {
return type.toString() + ": " + fingerprint + (deviceId != 0 ? " " + String.valueOf(deviceId) : "");
}
}
public static String lameUrlDecode(String url) {
return url.replace("%23", "#").replace("%25", "%");
}
public static String lameUrlEncode(String url) {
return url.replace("%", "%25").replace("#", "%23");
}
}