From c2ef2e23fc30961dedf5a8d924e4227bce25b1fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erkan=20I=C5=9EIK?= Date: Mon, 1 Jun 2026 16:01:17 +0300 Subject: [PATCH] feat: add hostname sanitization function and integrate it into user step processing --- src/steps/users.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/steps/users.rs b/src/steps/users.rs index 3178e9b..bcfad76 100644 --- a/src/steps/users.rs +++ b/src/steps/users.rs @@ -77,6 +77,24 @@ fn is_valid_hostname(s: &str) -> bool { s.chars().all(|c| c.is_ascii_alphanumeric() || c == '-') } +/// Otomatik hostname üretirken nokta, boşluk ve geçersiz karakterleri kaldırır. +fn sanitize_hostname(s: &str) -> String { + let mut hostname: String = s + .chars() + .filter(|c| c.is_ascii_alphanumeric()) + .collect(); + + if hostname.len() > 63 { + hostname.truncate(63); + } + + if hostname.is_empty() { + "host".to_string() + } else { + hostname + } +} + fn password_strength(p: &str) -> (String, egui::Color32) { let len = p.len(); let has_upper = p.chars().any(|c| c.is_uppercase()); @@ -112,13 +130,14 @@ impl InstallerStep for UsersStep { .unwrap_or_default() .trim() .to_string(); + let sys_hostname = sanitize_hostname(&sys_hostname); if !sys_hostname.is_empty() && sys_hostname != "localhost" { state.hostname = sys_hostname; } } // Hâlâ boşsa ve username varsa username-pc öner if state.hostname.is_empty() && !state.username.is_empty() { - state.hostname = format!("{}-pc", state.username); + state.hostname = sanitize_hostname(&format!("{}pc", state.username)); } }