Skip to content

Commit

Permalink
trim [ and ] from host string before used to connect by TcpStream
Browse files Browse the repository at this point in the history
  • Loading branch information
Van Tien Thanh committed Apr 22, 2022
1 parent b934f82 commit 204a65d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sqlx-core/src/net/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ pub enum Socket {

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

#[cfg(unix)]
Expand Down

0 comments on commit 204a65d

Please sign in to comment.