Prevent bad server entry

This commit is contained in:
Stefan Schüller 2019-03-03 21:58:10 +01:00
parent 125448b87b
commit b3b6fa0731
3 changed files with 15 additions and 3 deletions

View File

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

View File

@ -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();
});
}

View File

@ -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;
}