From 78e2e1bcc4a4a766ee601632a7b38e5c1e9e7618 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=AD?= <mvdan@mvdan.cc>
Date: Thu, 26 Sep 2013 20:16:08 +0200
Subject: [PATCH] Avoid crashes when appid or repoUri are empty

---
 src/org/fdroid/fdroid/AppDetails.java | 13 +++++++------
 src/org/fdroid/fdroid/FDroid.java     |  4 ++--
 src/org/fdroid/fdroid/ManageRepo.java |  3 +--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/org/fdroid/fdroid/AppDetails.java b/src/org/fdroid/fdroid/AppDetails.java
index 500a4f2d4..186db342f 100644
--- a/src/org/fdroid/fdroid/AppDetails.java
+++ b/src/org/fdroid/fdroid/AppDetails.java
@@ -197,7 +197,6 @@ public class AppDetails extends ListActivity {
         setContentView(R.layout.appdetails);
 
         Intent i = getIntent();
-        appid = "";
         Uri data = i.getData();
         if (data != null) {
             if (data.isHierarchical()) {
@@ -328,11 +327,13 @@ public class AppDetails extends ListActivity {
 
         Log.d("FDroid", "Getting application details for " + appid);
         app = null;
-        List<DB.App> apps = ((FDroidApp) getApplication()).getApps();
-        for (DB.App tapp : apps) {
-            if (tapp.id.equals(appid)) {
-                app = tapp;
-                break;
+        if (appid != null && appid.length() > 0) {
+            List<DB.App> apps = ((FDroidApp) getApplication()).getApps();
+            for (DB.App tapp : apps) {
+                if (tapp.id.equals(appid)) {
+                    app = tapp;
+                    break;
+                }
             }
         }
         if (app == null) {
diff --git a/src/org/fdroid/fdroid/FDroid.java b/src/org/fdroid/fdroid/FDroid.java
index 96547ba62..b3c4ad0a3 100644
--- a/src/org/fdroid/fdroid/FDroid.java
+++ b/src/org/fdroid/fdroid/FDroid.java
@@ -89,14 +89,14 @@ public class FDroid extends FragmentActivity {
                 String appid = data.getQueryParameter("fdid");
                 // If appid == null, we just browse all the apps.
                 // If appid != null, we browse the app specified.
-                if (appid != null) {
+                if (appid != null && appid.length() > 0) {
                     Intent call = new Intent(this, AppDetails.class);
                     call.putExtra("appid", appid);
                     startActivityForResult(call, REQUEST_APPDETAILS);
                 }
             } else {
                 String repoUri = data.getEncodedSchemeSpecificPart();
-                if (repoUri != null) {
+                if (repoUri != null && repoUri.length() > 0) {
                     Intent call = new Intent(this, ManageRepo.class);
                     call.putExtra("repoUri", repoUri);
                     startActivityForResult(call, REQUEST_MANAGEREPOS);
diff --git a/src/org/fdroid/fdroid/ManageRepo.java b/src/org/fdroid/fdroid/ManageRepo.java
index de2719afb..1e3882c9f 100644
--- a/src/org/fdroid/fdroid/ManageRepo.java
+++ b/src/org/fdroid/fdroid/ManageRepo.java
@@ -82,8 +82,7 @@ public class ManageRepo extends ListActivity {
 
         Intent i = getIntent();
         if (i.hasExtra("repoUri")) {
-            String repoUri = i.getStringExtra("repoUri");
-            addRepo(repoUri);
+            addRepo(i.getStringExtra("repoUri"));
             finish();
         }