From 90243404874a4c0fad282e3427c9b77dd8355cbd Mon Sep 17 00:00:00 2001 From: felixdoerre Date: Tue, 12 Apr 2022 12:11:11 +0200 Subject: [PATCH] fix: postgresql ipv6 host should not be enclosed in square brackets (#47522) --- pkg/tsdb/postgres/postgres.go | 4 ++-- pkg/tsdb/postgres/postgres_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/tsdb/postgres/postgres.go b/pkg/tsdb/postgres/postgres.go index 527102831b6..37e69c09ebc 100644 --- a/pkg/tsdb/postgres/postgres.go +++ b/pkg/tsdb/postgres/postgres.go @@ -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) } } diff --git a/pkg/tsdb/postgres/postgres_test.go b/pkg/tsdb/postgres/postgres_test.go index eb7278d47ff..45b9a1d030c 100644 --- a/pkg/tsdb/postgres/postgres_test.go +++ b/pkg/tsdb/postgres/postgres_test.go @@ -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",