Fix panic when parsing empty pgsql host (#28708)
Regression of #27723 Fix #28705
This commit is contained in:
parent
e522e774ca
commit
e75e9a0e7e
2 changed files with 5 additions and 1 deletions
|
@ -168,7 +168,7 @@ func getPostgreSQLConnectionString(dbHost, dbUser, dbPasswd, dbName, dbsslMode s
|
||||||
RawQuery: dbParam,
|
RawQuery: dbParam,
|
||||||
}
|
}
|
||||||
query := connURL.Query()
|
query := connURL.Query()
|
||||||
if dbHost[0] == '/' { // looks like a unix socket
|
if strings.HasPrefix(dbHost, "/") { // looks like a unix socket
|
||||||
query.Add("host", dbHost)
|
query.Add("host", dbHost)
|
||||||
connURL.Host = ":" + port
|
connURL.Host = ":" + port
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,10 @@ func Test_getPostgreSQLConnectionString(t *testing.T) {
|
||||||
SSLMode string
|
SSLMode string
|
||||||
Output string
|
Output string
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
Host: "", // empty means default
|
||||||
|
Output: "postgres://:@127.0.0.1:5432?sslmode=",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Host: "/tmp/pg.sock",
|
Host: "/tmp/pg.sock",
|
||||||
User: "testuser",
|
User: "testuser",
|
||||||
|
|
Loading…
Reference in a new issue