From 1d9174502cfc373a3ff83c80f87a93a8c973f900 Mon Sep 17 00:00:00 2001 From: enricobuehler Date: Thu, 26 Nov 2026 10:21:26 +0100 Subject: [PATCH] fix(console): store a typed host address bare The add and edit forms stored the address field as typed. A pasted host:port kept its port in the address, and a bracketed IPv6 was bracketed again by base_url, so neither host could be dialled. Both forms now go through the shared HostEdit::typed: the address is stored bare, and a pasted port replaces the port field's. --- crates/pf-ps5-app/src/ui/service.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/pf-ps5-app/src/ui/service.rs b/crates/pf-ps5-app/src/ui/service.rs index 1394884..f34bd91 100644 --- a/crates/pf-ps5-app/src/ui/service.rs +++ b/crates/pf-ps5-app/src/ui/service.rs @@ -769,6 +769,7 @@ impl Service { // ---- the host list ----------------------------------------------------------------- fn save_host(&mut self, name: String, addr: String, port: u16) { + let (addr, port) = typed(addr, port); self.store.edit(|state| { // Keyed by address, not fingerprint: a hand-typed host has none yet, so an // fp-keyed upsert would collide every one of them onto the same record. @@ -793,6 +794,7 @@ impl Service { } fn update_host(&mut self, key: &str, name: String, addr: String, port: u16) { + let (addr, port) = typed(addr, port); let edited = self.store.edit(|state| { let Some(i) = shared::find_known(&state.known_hosts, key) else { return false; @@ -1351,3 +1353,21 @@ fn to_model(games: &[GameEntry]) -> Vec { }) .collect() } + +/// A form's address as the store keeps it: bare, a pasted port in place of the field's. +fn typed(addr: String, port: u16) -> (String, u16) { + let edit = pf_client_core::trust::HostEdit::typed(String::new(), addr, port); + (edit.addr.unwrap_or_default(), edit.port.unwrap_or(port)) +} + +#[cfg(test)] +mod tests { + /// `base_url` brackets a bare IPv6 itself, and a pasted port is the one to dial. + #[test] + fn a_typed_address_is_stored_bare() { + let typed = |addr: &str| super::typed(addr.into(), 9777); + assert_eq!(typed(" desk.lan:9800 "), ("desk.lan".into(), 9800)); + assert_eq!(typed("[fd00::1]"), ("fd00::1".into(), 9777)); + assert_eq!(typed("192.168.1.20"), ("192.168.1.20".into(), 9777)); + } +}