Skip to content

Commit

Permalink
Fix incorrect PostgreSQL connection string for Unix sockets (#28865)
Browse files Browse the repository at this point in the history
Fix #28864
  • Loading branch information
sdvcrx authored Jan 20, 2024
1 parent 6c771a3 commit 80d4862
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/setting/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions modules/setting/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 80d4862

Please sign in to comment.