[geary/wip/714104-refine-account-dialog: 42/69] Fix hostname validator not dealing with whitespace, port no's.



commit a0c3754042e49d3908205f00dc6677caf69cc69c
Author: Michael Gratton <mike vee net>
Date:   Wed Sep 5 23:37:57 2018 +1000

    Fix hostname validator not dealing with whitespace, port no's.

 src/client/components/components-validator.vala | 56 ++++++++++++-------------
 1 file changed, 28 insertions(+), 28 deletions(-)
---
diff --git a/src/client/components/components-validator.vala b/src/client/components/components-validator.vala
index 9da21c75..4432c1b8 100644
--- a/src/client/components/components-validator.vala
+++ b/src/client/components/components-validator.vala
@@ -358,44 +358,44 @@ public class Components.NetworkAddressValidator : Validator {
             this.cancellable.cancel();
         }
 
+        Validator.Validity ret = this.state;
+
         GLib.NetworkAddress? address = null;
         try {
-            address = GLib.NetworkAddress.parse(value, this.default_port);
+            address = GLib.NetworkAddress.parse(
+                value.strip(), this.default_port
+            );
         } catch (GLib.Error err) {
+            this.validated_address = null;
+            ret = Validator.Validity.INVALID;
             debug("Error parsing host name \"%s\": %s", value, err.message);
         }
 
-        Validator.Validity ret = this.state;
-
-        if (address != null) {
-            // Only re-validate if changed
-            if (this.validated_address == null ||
+        // Only re-validate if changed
+        if (address != null && (
+                this.validated_address == null ||
                 this.validated_address.hostname != address.hostname ||
                 this.validated_address.port != address.port ||
-                this.validated_address.scheme != address.scheme) {
-
-                this.cancellable = new GLib.Cancellable();
-                this.resolver.lookup_by_name_async.begin(
-                    value.strip(), this.cancellable,
-                    (obj, res) => {
-                        try {
-                            this.resolver.lookup_by_name_async.end(res);
-                            this.validated_address = address;
-                            update_state(Validator.Validity.VALID);
-                        } catch (GLib.IOError.CANCELLED err) {
-                            this.validated_address = null;
-                        } catch (GLib.Error err) {
-                            this.validated_address = null;
-                            update_state(Validator.Validity.INVALID);
-                        }
-                        this.cancellable = null;
+                this.validated_address.scheme != address.scheme)) {
+            this.cancellable = new GLib.Cancellable();
+            this.resolver.lookup_by_name_async.begin(
+                address.hostname, this.cancellable,
+                (obj, res) => {
+                    try {
+                        this.resolver.lookup_by_name_async.end(res);
+                        this.validated_address = address;
+                        update_state(Validator.Validity.VALID);
+                    } catch (GLib.IOError.CANCELLED err) {
+                        this.validated_address = null;
+                    } catch (GLib.Error err) {
+                        this.validated_address = null;
+                        update_state(Validator.Validity.INVALID);
                     }
-                );
+                    this.cancellable = null;
+                }
+            );
 
-                ret = Validator.Validity.IN_PROGRESS;
-            }
-        } else {
-            ret = Validator.Validity.INVALID;
+            ret = Validator.Validity.IN_PROGRESS;
         }
 
         return ret;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]