Skip to content

Commit 131a8f0

Browse files
GiteaBotearl-warren
authored andcommitted
Fix incorrect PostgreSQL connection string for Unix sockets (go-gitea#28865) (go-gitea#28870)
Backport go-gitea#28865 by @sdvcrx Fix go-gitea#28864 Co-authored-by: sdvcrx <memory.silentvoyage@gmail.com> (cherry picked from commit 8c7bda8)
1 parent 6aa5554 commit 131a8f0

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
@@ -170,8 +170,8 @@ func getPostgreSQLConnectionString(dbHost, dbUser, dbPasswd, dbName, dbsslMode s
170170
RawQuery: dbParam,
171171
}
172172
query := connURL.Query()
173-
if strings.HasPrefix(dbHost, "/") { // looks like a unix socket
174-
query.Add("host", dbHost)
173+
if strings.HasPrefix(host, "/") { // looks like a unix socket
174+
query.Add("host", host)
175175
connURL.Host = ":" + port
176176
}
177177
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)