1
0
Fork 0
mirror of https://github.com/M66B/NetGuard.git synced 2024-12-25 09:21:14 +00:00

Trim addresses

This commit is contained in:
M66B 2018-12-03 17:14:17 +01:00
parent c1afc58e95
commit 3082031b4f

View file

@ -615,6 +615,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
String vpn4 = prefs.getString(name, null);
try {
checkAddress(vpn4);
prefs.edit().putString(name, vpn4.trim()).apply();
} catch (Throwable ex) {
prefs.edit().remove(name).apply();
((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
@ -629,6 +630,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
String vpn6 = prefs.getString(name, null);
try {
checkAddress(vpn6);
prefs.edit().putString(name, vpn6.trim()).apply();
} catch (Throwable ex) {
prefs.edit().remove(name).apply();
((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
@ -643,6 +645,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
String dns = prefs.getString(name, null);
try {
checkAddress(dns);
prefs.edit().putString(name, dns.trim()).apply();
} catch (Throwable ex) {
prefs.edit().remove(name).apply();
((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null);
@ -765,7 +768,9 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere
}
private void checkAddress(String address) throws IllegalArgumentException, UnknownHostException {
if (address == null || TextUtils.isEmpty(address.trim()))
if (address != null)
address = address.trim();
if (TextUtils.isEmpty(address))
throw new IllegalArgumentException("Bad address");
if (!Util.isNumericAddress(address))
throw new IllegalArgumentException("Bad address");