fix: harden address parsing edge cases

This commit is contained in:
ZacharyZcR
2026-06-01 04:03:46 +08:00
parent 8ec96bfe6d
commit 569d21a8bc
43 changed files with 273 additions and 137 deletions
+16 -2
View File
@@ -545,12 +545,26 @@ func TestConvertToTargetInfos(t *testing.T) {
},
},
{
name: "IPv6地址",
name: "裸IPv6地址缺少方括号",
ports: []string{"::1:8080"},
baseInfo: common.HostInfo{},
expectedLen: 0, // Split会产生多个部分,被判定为非法
expectedLen: 0,
validateFunc: nil,
},
{
name: "IPv6地址",
ports: []string{"[2001:db8::1]:8080"},
baseInfo: common.HostInfo{},
expectedLen: 1,
validateFunc: func(t *testing.T, infos []common.HostInfo) {
if infos[0].Host != "2001:db8::1" {
t.Errorf("Host = %q, 期望 '2001:db8::1'", infos[0].Host)
}
if infos[0].Port != 8080 {
t.Errorf("Port = %d, 期望 8080", infos[0].Port)
}
},
},
{
name: "域名+端口",
ports: []string{"example.com:80", "test.local:443"},