From 4c4f5de6d89dd6b1c686757fbd31f513f266a2bf Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Fri, 1 May 2026 01:28:54 +0800 Subject: [PATCH] feat: add IPv6 support for connection URLs by bracketing host addresses --- src-tauri/src/models/connection.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src-tauri/src/models/connection.rs b/src-tauri/src/models/connection.rs index 9b778585f..df58ea021 100644 --- a/src-tauri/src/models/connection.rs +++ b/src-tauri/src/models/connection.rs @@ -76,6 +76,7 @@ impl ConnectionConfig { } pub fn redacted_connection_url_with_host(&self, host: &str, port: u16) -> String { + let host = bracket_ipv6(host); let db_part = self .database .as_deref() @@ -118,6 +119,7 @@ impl ConnectionConfig { } pub fn connection_url_with_host(&self, host: &str, port: u16) -> String { + let host = bracket_ipv6(host); let db_part = self .database .as_deref() @@ -206,6 +208,14 @@ fn encode_url_part(value: &str) -> String { utf8_percent_encode(value, NON_ALPHANUMERIC).to_string() } +fn bracket_ipv6(host: &str) -> String { + if host.contains(':') && !host.starts_with('[') { + format!("[{host}]") + } else { + host.to_string() + } +} + #[cfg(test)] mod tests { use super::{ConnectionConfig, DatabaseType};