support unicode hostname

This commit is contained in:
sijie.sun
2024-08-04 09:21:00 +08:00
committed by Sijie.Sun
parent 5f0d71b0fe
commit 5e51784803
+5 -11
View File
@@ -258,21 +258,15 @@ impl ConfigLoader for TomlConfigLoader {
match hostname { match hostname {
Some(hostname) => { Some(hostname) => {
if !hostname.is_empty() { let hostname = hostname
let mut name = hostname
.chars() .chars()
.filter(|c| c.is_ascii_alphanumeric() || *c == '-' || *c == '_') .filter(|c| !c.is_control())
.take(32) .take(32)
.collect::<String>(); .collect::<String>();
if name.len() > 32 { if !hostname.is_empty() {
name = name.chars().take(32).collect::<String>(); self.set_hostname(Some(hostname.clone()));
} hostname
if hostname != name {
self.set_hostname(Some(name.clone()));
}
name
} else { } else {
self.set_hostname(None); self.set_hostname(None);
gethostname::gethostname().to_string_lossy().to_string() gethostname::gethostname().to_string_lossy().to_string()