From 372b8f0e93c893586afc1ca77ef6c21f1b172c41 Mon Sep 17 00:00:00 2001 From: Gusted Date: Mon, 11 Jul 2022 11:19:21 +0200 Subject: [PATCH 1/2] Use default values when provided values are empty - When provided values are empty like `:3000` would imply that host is empty, use the default value. - Resolves #20316 --- modules/setting/database.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/setting/database.go b/modules/setting/database.go index 87d56fbc930c1..1aebb022f1c73 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -156,6 +156,12 @@ func parsePostgreSQLHostPort(info string) (string, string) { } else if len(info) > 0 { host = info } + if host == "" { + host = "127.0.0.1" + } + if port == "" { + port = "5432" + } return host, port } @@ -183,5 +189,11 @@ func ParseMSSQLHostPort(info string) (string, string) { } else if len(info) > 0 { host = info } + if host == "" { + host = "127.0.0.1" + } + if port == "" { + port = "0" + } return host, port } From a9584a134728e2c3ba73818a9dd057d58762f6cf Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 13 Jul 2022 10:13:05 +0800 Subject: [PATCH 2/2] Update database.go --- modules/setting/database.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/setting/database.go b/modules/setting/database.go index 1aebb022f1c73..8fdd5f2bcb2ff 100644 --- a/modules/setting/database.go +++ b/modules/setting/database.go @@ -179,6 +179,7 @@ func getPostgreSQLConnectionString(dbHost, dbUser, dbPasswd, dbName, dbParam, db // ParseMSSQLHostPort splits the host into host and port func ParseMSSQLHostPort(info string) (string, string) { + // the default port "0" might be related to MSSQL's dynamic port, maybe it should be double-confirmed in the future host, port := "127.0.0.1", "0" if strings.Contains(info, ":") { host = strings.Split(info, ":")[0]