feat: add IPv6 support for connection URLs by bracketing host addresses

This commit is contained in:
t8y2 2026-05-01 01:28:54 +08:00
parent b43e67b4fc
commit 4c4f5de6d8
1 changed files with 10 additions and 0 deletions

View File

@ -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};