fix: postgresql ipv6 host should not be enclosed in square brackets (#47522)

This commit is contained in:
felixdoerre 2022-04-12 12:11:11 +02:00 committed by GitHub
parent eca61e6dd7
commit 9024340487
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -140,7 +140,7 @@ func (s *Service) generateConnectionString(dsInfo sqleng.DataSourceInfo) (string
}
} else {
if index == v6Index+1 {
host = dsInfo.URL[0:index]
host = dsInfo.URL[1 : index-1]
var err error
port, err = strconv.Atoi(dsInfo.URL[index+1:])
if err != nil {
@ -149,7 +149,7 @@ func (s *Service) generateConnectionString(dsInfo sqleng.DataSourceInfo) (string
logger.Debug("Generating ipv6 connection string with network host/port pair", "host", host, "port", port)
} else {
host = dsInfo.URL
host = dsInfo.URL[1 : len(dsInfo.URL)-1]
logger.Debug("Generating ipv6 connection string with network host", "host", host)
}
}

View File

@ -74,7 +74,7 @@ func TestGenerateConnectionString(t *testing.T) {
password: "password",
database: "database",
tlsSettings: tlsSettings{Mode: "verify-full"},
expConnStr: "user='user' password='password' host='[::1]' dbname='database' sslmode='verify-full'",
expConnStr: "user='user' password='password' host='::1' dbname='database' sslmode='verify-full'",
},
{
desc: "Ipv6/port host",
@ -83,7 +83,7 @@ func TestGenerateConnectionString(t *testing.T) {
password: "password",
database: "database",
tlsSettings: tlsSettings{Mode: "verify-full"},
expConnStr: "user='user' password='password' host='[::1]' dbname='database' port=1234 sslmode='verify-full'",
expConnStr: "user='user' password='password' host='::1' dbname='database' port=1234 sslmode='verify-full'",
},
{
desc: "Invalid port",