From b3b6fa0731430b13d89e76d32c3fcf1fe324ee62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Schu=CC=88ller?= Date: Sun, 3 Mar 2019 21:58:10 +0100 Subject: [PATCH] Prevent bad server entry --- CHANGELOG.md | 3 +++ .../peertube/activity/SelectServerActivity.java | 11 ++++++++--- .../net/schueller/peertube/helper/APIUrlHelper.java | 4 ++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6a0853..c56cc89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +### Version 1.0.29 Tag: v1.0.29 (2019-03-03) +* Prevent entry of bad URL + ### Version 1.0.28 Tag: v1.0.28 (2019-03-03) * Server selection * Lots of translations diff --git a/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java b/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java index d29a8fa..b2da65f 100644 --- a/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/SelectServerActivity.java @@ -13,6 +13,7 @@ import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; import android.util.Log; +import android.util.Patterns; import android.view.View; import android.widget.Button; import android.widget.TextView; @@ -65,10 +66,14 @@ public class SelectServerActivity extends AppCompatActivity { String serverUrl = APIUrlHelper.cleanServerUrl(selectedUrl.getText().toString()); - editor.putString("pref_api_base", serverUrl); - editor.apply(); + if (!Patterns.WEB_URL.matcher(serverUrl).matches()) { + Toast.makeText(this, R.string.invalid_url, Toast.LENGTH_LONG).show(); + } else { + editor.putString("pref_api_base", serverUrl); + editor.apply(); + this.finish(); + } - this.finish(); }); } 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 3cc5a00..cf24b2f 100644 --- a/app/src/main/java/net/schueller/peertube/helper/APIUrlHelper.java +++ b/app/src/main/java/net/schueller/peertube/helper/APIUrlHelper.java @@ -20,7 +20,9 @@ package net.schueller.peertube.helper; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; +import android.util.Patterns; import android.webkit.URLUtil; +import android.widget.Toast; import net.schueller.peertube.R; @@ -53,6 +55,8 @@ public class APIUrlHelper{ String cleanUrl = url.toLowerCase(); + cleanUrl = cleanUrl.replace(" ", ""); + if (!cleanUrl.startsWith("http")) { cleanUrl = "https://" + cleanUrl; }