httpclient: 清理 ssrf.go S1017 lint 警告

matchAllowedHost 里两处 if strings.HasPrefix(...) pattern = pattern[N:]
替成无条件 strings.TrimPrefix, 行为完全等价 (前缀不匹配时 TrimPrefix
是 no-op). 触发 S1017 (Should replace this if statement with an
unconditional strings.TrimPrefix).

净 -4 行, 函数语义不变, matchAllowedHost 现有测试 (ssrf_test.go)
覆盖的精确/后缀/wildcard 三种 host 匹配路径都不变.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
tao.chen
2026-07-13 16:26:17 +08:00
co-authored by Claude
parent 3bc8bd49f6
commit 475e353850
+2 -6
View File
@@ -116,12 +116,8 @@ func matchAllowedHost(host, pattern string) bool {
return true
}
if strings.HasPrefix(pattern, "*.") {
pattern = pattern[2:]
}
if strings.HasPrefix(pattern, ".") {
pattern = pattern[1:]
}
pattern = strings.TrimPrefix(pattern, "*.")
pattern = strings.TrimPrefix(pattern, ".")
return host == pattern || strings.HasSuffix(host, "."+pattern)
}