pb: fix IPv6 double brackets in ServerAddress formatting (#8329)

* pb: fix IPv6 double brackets in ServerAddress formatting

* pb: refactor IPv6 tests into table-driven test

* util: add JoinHostPortStr and use it in pb to avoid unsafe port parsing
This commit is contained in:
Chris Lu
2026-02-12 18:11:03 -08:00
committed by GitHub
parent 796f23f68a
commit 1e4f30c56f
3 changed files with 41 additions and 5 deletions

View File

@@ -58,11 +58,14 @@ func selectIpV4(netInterfaces []net.Interface, isIpV4 bool) string {
}
func JoinHostPort(host string, port int) string {
portStr := strconv.Itoa(port)
return JoinHostPortStr(host, strconv.Itoa(port))
}
func JoinHostPortStr(host string, port string) string {
if strings.HasPrefix(host, "[") && strings.HasSuffix(host, "]") {
return host + ":" + portStr
return host + ":" + port
}
return net.JoinHostPort(host, portStr)
return net.JoinHostPort(host, port)
}
// GetVolumeServerId returns the volume server ID.