plugin/forward: fix parsing error when handling TLS+IPv6 address (#7848)

This commit is contained in:
yangsenzk
2026-02-25 18:21:39 +08:00
committed by GitHub
parent 7ae1c40db2
commit 5b7da1fbf7
3 changed files with 23 additions and 1 deletions

View File

@@ -99,17 +99,28 @@ func parseForward(c *caddy.Controller) ([]*Forward, error) {
// Splits the zone, preserving any port that comes after the zone
func splitZone(host string) (newHost string, zone string) {
trans, host, found := strings.Cut(host, "://")
if !found {
host, trans = trans, ""
}
newHost = host
if strings.Contains(host, "%") {
lastPercent := strings.LastIndex(host, "%")
newHost = host[:lastPercent]
if strings.HasPrefix(newHost, "[") {
newHost = newHost + "]"
}
zone = host[lastPercent+1:]
if strings.Contains(zone, ":") {
lastColon := strings.LastIndex(zone, ":")
newHost += zone[lastColon:]
zone = zone[:lastColon]
zone = strings.TrimSuffix(zone, "]")
}
}
if trans != "" {
newHost = trans + "://" + newHost
}
return
}