Skip to content

Commit b7c6ec9

Browse files
Gustedlunnywxiaoguang
authored
Use default values when provided values are empty (#20318)
* 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 * Update database.go Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent f67a103 commit b7c6ec9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

modules/setting/database.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ func parsePostgreSQLHostPort(info string) (string, string) {
156156
} else if len(info) > 0 {
157157
host = info
158158
}
159+
if host == "" {
160+
host = "127.0.0.1"
161+
}
162+
if port == "" {
163+
port = "5432"
164+
}
159165
return host, port
160166
}
161167

@@ -173,6 +179,7 @@ func getPostgreSQLConnectionString(dbHost, dbUser, dbPasswd, dbName, dbParam, db
173179

174180
// ParseMSSQLHostPort splits the host into host and port
175181
func ParseMSSQLHostPort(info string) (string, string) {
182+
// the default port "0" might be related to MSSQL's dynamic port, maybe it should be double-confirmed in the future
176183
host, port := "127.0.0.1", "0"
177184
if strings.Contains(info, ":") {
178185
host = strings.Split(info, ":")[0]
@@ -183,5 +190,11 @@ func ParseMSSQLHostPort(info string) (string, string) {
183190
} else if len(info) > 0 {
184191
host = info
185192
}
193+
if host == "" {
194+
host = "127.0.0.1"
195+
}
196+
if port == "" {
197+
port = "0"
198+
}
186199
return host, port
187200
}

0 commit comments

Comments
 (0)