]> git.ktnx.net Git - mobile-ledger.git/commitdiff
profile editor: validate entered URL
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 13 Jul 2019 05:53:46 +0000 (08:53 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 13 Jul 2019 05:54:11 +0000 (08:54 +0300)
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java
app/src/main/res/values-bg/strings.xml
app/src/main/res/values/strings.xml

index b51ddbb54de6c1cb53e6780a2b7586b7df3df895..c6dbc6a587c1799244b6656de63d95c4bba9cf5f 100644 (file)
@@ -46,6 +46,8 @@ import net.ktnx.mobileledger.utils.Colors;
 
 import org.jetbrains.annotations.NotNull;
 
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Objects;
 
@@ -321,11 +323,20 @@ public class ProfileDetailFragment extends Fragment implements HueRingDialog.Hue
             profileNameLayout.setError(getResources().getText(R.string.err_profile_name_empty));
         }
 
-        val = String.valueOf(url.getText());
-        if (val.trim().isEmpty()) {
+        val = String.valueOf(url.getText()).trim();
+        if (val.isEmpty()) {
             valid = false;
             urlLayout.setError(getResources().getText(R.string.err_profile_url_empty));
         }
+        try {
+            URL url = new URL(val);
+            String host = url.getHost();
+            if (host == null || host.isEmpty()) throw new MalformedURLException("Missing host");
+        }
+        catch (MalformedURLException e) {
+            valid = false;
+            urlLayout.setError(getResources().getText(R.string.err_invalid_url));
+        }
         if (useAuthentication.isChecked()) {
             val = String.valueOf(userName.getText());
             if (val.trim().isEmpty()) {
index 64c262e9e87047100e1c032a2ceba815ca8366fb..5b61f83ead1573b1cce2f610cc36cc98b7a1f0b3 100644 (file)
     <string name="remove_profile_dialog_message">Потвърдете окончателното премахване на профила</string>
     <string name="Remove">Премахване</string>
     <string name="text_loading">Зареждане…</string>
+    <string name="err_invalid_url">Грешен или непълен адрес</string>
 
 </resources>
index 7e4cf10f38df992c2cc90ade90d159f562d08518..6d1632d87095b442634f14e0121b8eb4b4802173 100644 (file)
     <string name="remove_profile_dialog_message">Permanently remove this profile?</string>
     <string name="Remove">Remove</string>
     <string name="text_loading">Loading…</string>
+    <string name="err_invalid_url">Invalid URL</string>
 </resources>