Skip to content

Commit df5f827

Browse files
Van Tien ThanhThanh Van
Van Tien Thanh
authored and
Thanh Van
committed
trim [ and ] from host string before used to connect by TcpStream
1 parent fa5c436 commit df5f827

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

sqlx-core/src/net/socket.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ pub enum Socket {
1717

1818
impl Socket {
1919
pub async fn connect_tcp(host: &str, port: u16) -> io::Result<Self> {
20-
TcpStream::connect((host, port)).await.map(Socket::Tcp)
20+
// Trim square brackets from host if it's an IPv6 address as the `url` crate doesn't do that.
21+
TcpStream::connect((host.trim_matches(|c| c == "[" || c == "]"), port))
22+
.await
23+
.map(Socket::Tcp)
2124
}
2225

2326
#[cfg(unix)]

0 commit comments

Comments
 (0)