diff --git a/src-tauri/src/models/connection.rs b/src-tauri/src/models/connection.rs index 9b778585fe..df58ea021a 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};