- Prevent fatal when server URL is invalid

This commit is contained in:
Stefan Schueller 2018-12-02 14:59:14 +01:00
parent 7120a36091
commit 57c3079c68
1 changed files with 8 additions and 1 deletions

View File

@ -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) {