From 57c3079c6837fdb78391963999b6e39cc959ef8b Mon Sep 17 00:00:00 2001 From: Stefan Schueller Date: Sun, 2 Dec 2018 14:59:14 +0100 Subject: [PATCH] - Prevent fatal when server URL is invalid --- .../java/net/schueller/peertube/helper/APIUrlHelper.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/net/schueller/peertube/helper/APIUrlHelper.java b/app/src/main/java/net/schueller/peertube/helper/APIUrlHelper.java index 6e60f4f..cfed405 100644 --- a/app/src/main/java/net/schueller/peertube/helper/APIUrlHelper.java +++ b/app/src/main/java/net/schueller/peertube/helper/APIUrlHelper.java @@ -3,6 +3,7 @@ package net.schueller.peertube.helper; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; +import android.webkit.URLUtil; import net.schueller.peertube.R; @@ -10,7 +11,13 @@ public class APIUrlHelper{ public static String getUrl(Context context) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context); - return sharedPref.getString("pref_api_base", context.getResources().getString(R.string.pref_default_api_base_url)); + + // validate URL is valid + String URL = sharedPref.getString("pref_api_base", context.getResources().getString(R.string.pref_default_api_base_url)); + if (!URLUtil.isValidUrl(URL)) { + return "http://invalid"; + } + return URL; } public static String getUrlWithVersion(Context context) {