From 56933cdbd686a3a2cafa68c7a57aa3c655670d4e Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Fri, 11 Jul 2014 17:03:40 -0400 Subject: [PATCH] sanitize URL from clipboard and parse fingerprint (fixes #50) Instead of just sticking whatever URL is in the clipboard into the "Add Repo" dialog, this attempts to sanitize the URL in case it has some garbage or came from a QR Code, and therefore was all uppercase (that makes for smaller QR Codes). It also checks if there is a fingerprint in the query string of the URL, and sticks that into the fingerprint box. fixes #50 https://gitlab.com/fdroid/fdroidclient/issues/50 --- .../fdroid/views/ManageReposActivity.java | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/org/fdroid/fdroid/views/ManageReposActivity.java b/src/org/fdroid/fdroid/views/ManageReposActivity.java index 00b3463c7..9fe318a38 100644 --- a/src/org/fdroid/fdroid/views/ManageReposActivity.java +++ b/src/org/fdroid/fdroid/views/ManageReposActivity.java @@ -276,7 +276,31 @@ public class ManageReposActivity extends ActionBarActivity { } private void showAddRepo() { - showAddRepo(getNewRepoUri(), null); + /* + * If there is text in the clipboard, and it looks like a URL, use that. + * Otherwise use "https://" as default repo string. + */ + ClipboardCompat clipboard = ClipboardCompat.create(this); + String text = clipboard.getText(); + String fingerprint = null; + if (!TextUtils.isEmpty(text)) { + try { + new URL(text); + Uri uri = Uri.parse(text); + fingerprint = uri.getQueryParameter("fingerprint"); + // uri might contain a QR-style, all uppercase URL: + if (TextUtils.isEmpty(fingerprint)) + fingerprint = uri.getQueryParameter("FINGERPRINT"); + text = NewRepoConfig.sanitizeRepoUri(uri); + } catch (MalformedURLException e) { + text = null; + } + } + + if (TextUtils.isEmpty(text)) { + text = DEFAULT_NEW_REPO_TEXT; + } + showAddRepo(text, fingerprint); } private void showAddRepo(String newAddress, String newFingerprint) { @@ -421,27 +445,6 @@ public class ManageReposActivity extends ActionBarActivity { } } - /** - * If there is text in the clipboard, and it looks like a URL, use that. - * Otherwise return "https://". - */ - private String getNewRepoUri() { - ClipboardCompat clipboard = ClipboardCompat.create(this); - String text = clipboard.getText(); - if (text != null) { - try { - new URL(text); - } catch (MalformedURLException e) { - text = null; - } - } - - if (text == null) { - text = DEFAULT_NEW_REPO_TEXT; - } - return text; - } - private void addRepoFromIntent(Intent intent) { /* an URL from a click, NFC, QRCode scan, etc */ NewRepoConfig newRepoConfig = new NewRepoConfig(this, intent);