tools: 清理 fetch_url.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).
跟 475e353 在 httpclient/ssrf.go 上做的清理一模一样, 当时
只清了一处, fetch_url.go 里 copy 了同款 pattern 漏了.
净 -4 行, 函数语义不变, 现有测试 (fetch_url_test.go 覆盖的精确
/ 后缀 / wildcard 三种 host 匹配路径) 不变.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -209,12 +209,8 @@ func hostAllowed(host string, allowed []string) bool {
|
|||||||
if pattern == host {
|
if pattern == host {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(pattern, "*.") {
|
pattern = strings.TrimPrefix(pattern, "*.")
|
||||||
pattern = pattern[2:]
|
pattern = strings.TrimPrefix(pattern, ".")
|
||||||
}
|
|
||||||
if strings.HasPrefix(pattern, ".") {
|
|
||||||
pattern = pattern[1:]
|
|
||||||
}
|
|
||||||
if host == pattern || strings.HasSuffix(host, "."+pattern) {
|
if host == pattern || strings.HasSuffix(host, "."+pattern) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user