update host validation rule

This commit is contained in:
yggverse 2025-07-29 12:10:53 +03:00
parent 0911aba08c
commit 07c7fc4836

View File

@ -163,15 +163,12 @@ fn validate(host: &Entry) -> bool {
} }
fn validate_host(value: &str) -> Result<(), String> { fn validate_host(value: &str) -> Result<(), String> {
match gtk::gio::NetworkAddress::parse(value, 0) { // https://docs.gtk.org/gio/property.SimpleProxyResolver.ignore-hosts.html
Ok(address) => { match gtk::gio::NetworkAddress::parse(
use gtk::prelude::NetworkAddressExt; value.trim_start_matches('.').trim_start_matches('*'),
if address.hostname() != value { 0,
Err("Hostname or IP address could not be parsed properly".to_string()) ) {
} else { Ok(_) => Ok(()),
Ok(())
}
}
Err(e) => Err(format!("Valid hostname or IP address is required: `{e}`")), Err(e) => Err(format!("Valid hostname or IP address is required: `{e}`")),
} }
} }