From 00f554fad3d18986f160d860e828bfeca6b65519 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Fri, 17 Feb 2023 23:30:38 +0800 Subject: [PATCH] fix: parsing ipv6 doh error --- config/config.go | 41 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/config/config.go b/config/config.go index 498b069f..d71fc63f 100644 --- a/config/config.go +++ b/config/config.go @@ -890,29 +890,24 @@ func parseNameServer(servers []string, preferH3 bool) ([]dns.NameServer, error) addr, err = hostWithDefaultPort(u.Host, "853") dnsNetType = "tcp-tls" // DNS over TLS case "https": - host := u.Host - proxyAdapter = "" - if _, _, err := net.SplitHostPort(host); err != nil && strings.Contains(err.Error(), "missing port in address") { - host = net.JoinHostPort(host, "443") - } else { - if err != nil { - return nil, err - } - } - clearURL := url.URL{Scheme: "https", Host: host, Path: u.Path} - addr = clearURL.String() - dnsNetType = "https" // DNS over HTTPS - if len(u.Fragment) != 0 { - for _, s := range strings.Split(u.Fragment, "&") { - arr := strings.Split(s, "=") - if len(arr) == 0 { - continue - } else if len(arr) == 1 { - proxyAdapter = arr[0] - } else if len(arr) == 2 { - params[arr[0]] = arr[1] - } else { - params[arr[0]] = strings.Join(arr[1:], "=") + addr, err = hostWithDefaultPort(u.Host, "443") + if err == nil { + proxyAdapter = "" + clearURL := url.URL{Scheme: "https", Host: addr, Path: u.Path} + addr = clearURL.String() + dnsNetType = "https" // DNS over HTTPS + if len(u.Fragment) != 0 { + for _, s := range strings.Split(u.Fragment, "&") { + arr := strings.Split(s, "=") + if len(arr) == 0 { + continue + } else if len(arr) == 1 { + proxyAdapter = arr[0] + } else if len(arr) == 2 { + params[arr[0]] = arr[1] + } else { + params[arr[0]] = strings.Join(arr[1:], "=") + } } } }