fix: parse error

This commit is contained in:
Skyxim 2023-01-28 16:09:14 +08:00
parent a06b387acc
commit 2cf66f41cb

View File

@ -4,7 +4,7 @@ import (
"container/list" "container/list"
"errors" "errors"
"fmt" "fmt"
"net" "net"
"net/netip" "net/netip"
"net/url" "net/url"
"os" "os"
@ -841,17 +841,16 @@ func parseHosts(cfg *RawConfig) (*trie.DomainTrie[netip.Addr], error) {
func hostWithDefaultPort(host string, defPort string) (string, error) { func hostWithDefaultPort(host string, defPort string) (string, error) {
hostname, port, err := net.SplitHostPort(host) hostname, port, err := net.SplitHostPort(host)
if err != nil&&!strings.Contains(err.Error(),"missing port in address") { if err != nil {
return "", err if !strings.Contains(err.Error(), "missing port in address") {
return "", err
}
host = host + ":" + defPort
if hostname, port, err = net.SplitHostPort(host); err != nil {
return "", err
}
} }
if port == "" {
port = defPort
}
if hostname==""{
hostname=host
}
return net.JoinHostPort(hostname, port), nil return net.JoinHostPort(hostname, port), nil
} }
@ -940,17 +939,17 @@ func parsePureDNSServer(server string) string {
return "udp://" + server return "udp://" + server
} }
if ip,err := netip.ParseAddr(server); err != nil { if ip, err := netip.ParseAddr(server); err != nil {
if strings.Contains(server, "://") { if strings.Contains(server, "://") {
return server return server
} }
return addPre(server) return addPre(server)
} else { } else {
if ip.Is4(){ if ip.Is4() {
return addPre(server) return addPre(server)
}else{ } else {
return addPre("["+server+"]") return addPre("[" + server + "]")
} }
} }
} }
func parseNameServerPolicy(nsPolicy map[string]string, preferH3 bool) (map[string]dns.NameServer, error) { func parseNameServerPolicy(nsPolicy map[string]string, preferH3 bool) (map[string]dns.NameServer, error) {