mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	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 <xiaolunwen@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		@@ -156,6 +156,12 @@ func parsePostgreSQLHostPort(info string) (string, string) {
 | 
				
			|||||||
	} else if len(info) > 0 {
 | 
						} else if len(info) > 0 {
 | 
				
			||||||
		host = info
 | 
							host = info
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if host == "" {
 | 
				
			||||||
 | 
							host = "127.0.0.1"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if port == "" {
 | 
				
			||||||
 | 
							port = "5432"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return host, port
 | 
						return host, port
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -173,6 +179,7 @@ func getPostgreSQLConnectionString(dbHost, dbUser, dbPasswd, dbName, dbParam, db
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// ParseMSSQLHostPort splits the host into host and port
 | 
					// ParseMSSQLHostPort splits the host into host and port
 | 
				
			||||||
func ParseMSSQLHostPort(info string) (string, string) {
 | 
					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"
 | 
						host, port := "127.0.0.1", "0"
 | 
				
			||||||
	if strings.Contains(info, ":") {
 | 
						if strings.Contains(info, ":") {
 | 
				
			||||||
		host = strings.Split(info, ":")[0]
 | 
							host = strings.Split(info, ":")[0]
 | 
				
			||||||
@@ -183,5 +190,11 @@ func ParseMSSQLHostPort(info string) (string, string) {
 | 
				
			|||||||
	} else if len(info) > 0 {
 | 
						} else if len(info) > 0 {
 | 
				
			||||||
		host = info
 | 
							host = info
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if host == "" {
 | 
				
			||||||
 | 
							host = "127.0.0.1"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if port == "" {
 | 
				
			||||||
 | 
							port = "0"
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	return host, port
 | 
						return host, port
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user