From 7dc07bdad61c692b210323cdc462192b09d715c0 Mon Sep 17 00:00:00 2001 From: Michael Gratton Date: Wed, 6 Mar 2019 18:38:44 +1100 Subject: [PATCH] Fix NetworkAddressValidator not updating port number Ensure the validated address is updated even if we know it is valid, since the port number may have changed. Fixes #294 --- .../components/components-validator.vala | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/client/components/components-validator.vala b/src/client/components/components-validator.vala index 257d8195..199751cd 100644 --- a/src/client/components/components-validator.vala +++ b/src/client/components/components-validator.vala @@ -453,30 +453,35 @@ public class Components.NetworkAddressValidator : Validator { debug("Error parsing host name \"%s\": %s", value, err.message); } - // Only re-validate if previously invalid or the host has - // changed - if (address != null && ( - this.validated_address == null || - this.validated_address.hostname != address.hostname)) { - 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, reason); - } catch (GLib.IOError.CANCELLED err) { - this.validated_address = null; - } catch (GLib.Error err) { - this.validated_address = null; - update_state(Validator.Validity.INVALID, reason); + if (address != null) { + // Re-validate if previously invalid or the host has + // changed + if (this.validated_address == null || + this.validated_address.hostname != address.hostname) { + 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, reason); + } catch (GLib.IOError.CANCELLED err) { + this.validated_address = null; + } catch (GLib.Error err) { + this.validated_address = null; + update_state(Validator.Validity.INVALID, reason); + } + this.cancellable = null; } - this.cancellable = null; - } - ); - - ret = Validator.Validity.IN_PROGRESS; + ); + ret = Validator.Validity.IN_PROGRESS; + } else { + // Update the validated address in case the port + // number is being edited and has changed + this.validated_address = address; + ret = Validator.Validity.VALID; + } } return ret;