diff options
author | sdvcrx <memory.silentvoyage@gmail.com> | 2024-01-21 00:04:47 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-20 16:04:47 +0000 |
commit | 80d48621cdf484247f70ddd653fb4c47a640317a (patch) | |
tree | 0cd381a1969ebb0248959e9c08d6cf63ec916504 | |
parent | 6c771a311b09c511d837dda79c84264dcf4abb47 (diff) | |
download | gitea-80d48621cdf484247f70ddd653fb4c47a640317a.tar.gz gitea-80d48621cdf484247f70ddd653fb4c47a640317a.zip |
Fix incorrect PostgreSQL connection string for Unix sockets (#28865)
Fix #28864
-rw-r--r-- | modules/setting/database.go | 4 | ||||
-rw-r--r-- | modules/setting/database_test.go | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/modules/setting/database.go b/modules/setting/database.go index 0b0488ce85..e200b15b2e 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.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) diff --git a/modules/setting/database_test.go b/modules/setting/database_test.go index 14e0a6ac02..a742d54f8c 100644 --- a/modules/setting/database_test.go +++ b/modules/setting/database_test.go @@ -78,6 +78,14 @@ func Test_getPostgreSQLConnectionString(t *testing.T) { 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", Passwd: "I love Gitea!", |