Skip to content

Commit

Permalink
Fix panic when parsing empty pgsql host (#28708) (#28709)
Browse files Browse the repository at this point in the history
Backport #28708 by wxiaoguang

Regression of #27723
Fix #28705

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
  • Loading branch information
GiteaBot and wxiaoguang authored Jan 6, 2024
1 parent e67c819 commit 7f833d8
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 7f833d8

Please sign in to comment.