Skip to content

Commit

Permalink
Fix panic when parsing empty pgsql host (go-gitea#28708)
Browse files Browse the repository at this point in the history
Regression of go-gitea#27723
Fix go-gitea#28705
  • Loading branch information
wxiaoguang authored and GiteaBot committed Jan 6, 2024
1 parent e67c819 commit 4ab323a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/setting/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func getPostgreSQLConnectionString(dbHost, dbUser, dbPasswd, dbName, dbsslMode s
RawQuery: dbParam,
}
query := connURL.Query()
if dbHost[0] == '/' { // looks like a unix socket
if strings.HasPrefix(dbHost, "/") { // looks like a unix socket
query.Add("host", dbHost)
connURL.Host = ":" + port
}
Expand Down
4 changes: 4 additions & 0 deletions modules/setting/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func Test_getPostgreSQLConnectionString(t *testing.T) {
SSLMode string
Output string
}{
{
Host: "", // empty means default
Output: "postgres://:@127.0.0.1:5432?sslmode=",
},
{
Host: "/tmp/pg.sock",
User: "testuser",
Expand Down

0 comments on commit 4ab323a

Please sign in to comment.