Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-25 03:06:10 +01:00

Fix panic when parsing empty pgsql host (#28708) (#28709)

Backport #28708 by wxiaoguang

Regression of #27723
Fix #28705

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Giteabot 2024-01-06 20:05:49 +08:00 committed by GitHub
parent e67c819cf4
commit 7f833d8f71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -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
} }

View file

@ -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",