Skip to content

Commit 8c7bda8

Browse files
GiteaBotsdvcrx
andauthored
Fix incorrect PostgreSQL connection string for Unix sockets (#28865) (#28870)
Backport #28865 by @sdvcrx Fix #28864 Co-authored-by: sdvcrx <memory.silentvoyage@gmail.com>
1 parent b7e32b2 commit 8c7bda8

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

modules/setting/database.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ func getPostgreSQLConnectionString(dbHost, dbUser, dbPasswd, dbName, dbsslMode s
168168
RawQuery: dbParam,
169169
}
170170
query := connURL.Query()
171-
if strings.HasPrefix(dbHost, "/") { // looks like a unix socket
172-
query.Add("host", dbHost)
171+
if strings.HasPrefix(host, "/") { // looks like a unix socket
172+
query.Add("host", host)
173173
connURL.Host = ":" + port
174174
}
175175
query.Set("sslmode", dbsslMode)

modules/setting/database_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ func Test_getPostgreSQLConnectionString(t *testing.T) {
7777
SSLMode: "false",
7878
Output: "postgres://testuser:space%20space%20%21%23$%25%5E%5E%25%5E%60%60%60-=%3F=@:5432/gitea?host=%2Ftmp%2Fpg.sock&sslmode=false",
7979
},
80+
{
81+
Host: "/tmp/pg.sock:6432",
82+
User: "testuser",
83+
Passwd: "pass",
84+
Name: "gitea",
85+
SSLMode: "false",
86+
Output: "postgres://testuser:pass@:6432/gitea?host=%2Ftmp%2Fpg.sock&sslmode=false",
87+
},
8088
{
8189
Host: "localhost",
8290
User: "pgsqlusername",

0 commit comments

Comments
 (0)