Fix incorrect PostgreSQL connection string for Unix sockets (#28865)

Fix #28864
pull/27800/merge
sdvcrx 10 months ago committed by GitHub
parent 6c771a311b
commit 80d48621cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      modules/setting/database.go
  2. 8
      modules/setting/database_test.go

@ -169,8 +169,8 @@ func getPostgreSQLConnectionString(dbHost, dbUser, dbPasswd, dbName, dbsslMode s
RawQuery: dbParam,
}
query := connURL.Query()
if strings.HasPrefix(dbHost, "/") { // looks like a unix socket
query.Add("host", dbHost)
if strings.HasPrefix(host, "/") { // looks like a unix socket
query.Add("host", host)
connURL.Host = ":" + port
}
query.Set("sslmode", dbsslMode)

@ -77,6 +77,14 @@ func Test_getPostgreSQLConnectionString(t *testing.T) {
SSLMode: "false",
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",
},
{
Host: "/tmp/pg.sock:6432",
User: "testuser",
Passwd: "pass",
Name: "gitea",
SSLMode: "false",
Output: "postgres://testuser:pass@:6432/gitea?host=%2Ftmp%2Fpg.sock&sslmode=false",
},
{
Host: "localhost",
User: "pgsqlusername",

Loading…
Cancel
Save