diff --git a/app/dns/dns_test.go b/app/dns/dns_test.go index 9ec5c9c8a..677b80c6c 100644 --- a/app/dns/dns_test.go +++ b/app/dns/dns_test.go @@ -18,6 +18,7 @@ import ( "github.com/v2fly/v2ray-core/v5/common" "github.com/v2fly/v2ray-core/v5/common/net" "github.com/v2fly/v2ray-core/v5/common/serial" + "github.com/v2fly/v2ray-core/v5/common/strmatcher" feature_dns "github.com/v2fly/v2ray-core/v5/features/dns" "github.com/v2fly/v2ray-core/v5/proxy/freedom" "github.com/v2fly/v2ray-core/v5/testing/servers/udp" @@ -104,6 +105,16 @@ func (*staticHandler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) { case q.Name == "Mijia\\ Cloud." && q.Qtype == dns.TypeA: rr, _ := dns.NewRR("Mijia\\ Cloud. IN A 127.0.0.1") ans.Answer = append(ans.Answer, rr) + + case q.Name == "xn--vi8h.ws." /* 🍕.ws */ && q.Qtype == dns.TypeA: + rr, err := dns.NewRR("xn--vi8h.ws. IN A 208.100.42.200") + common.Must(err) + ans.Answer = append(ans.Answer, rr) + + case q.Name == "xn--l8jaaa.com." /* ああああ.com */ && q.Qtype == dns.TypeA: + rr, err := dns.NewRR("xn--l8jaaa.com. IN AAAA a:a:a:a::aaaa") + common.Must(err) + ans.Answer = append(ans.Answer, rr) } } w.WriteMsg(ans) @@ -251,6 +262,28 @@ func TestUDPServer(t *testing.T) { } } + { + ips, err := client.LookupIP(common.Must2(strmatcher.ToDomain("🍕.ws")).(string)) + if err != nil { + t.Fatal("unexpected error: ", err) + } + + if r := cmp.Diff(ips, []net.IP{{208, 100, 42, 200}}); r != "" { + t.Fatal(r) + } + } + + { + ips, err := client.LookupIP(common.Must2(strmatcher.ToDomain("ああああ.com")).(string)) + if err != nil { + t.Fatal("unexpected error: ", err) + } + + if r := cmp.Diff(ips, []net.IP{{0, 0xa, 0, 0xa, 0, 0xa, 0, 0xa, 0, 0, 0, 0, 0, 0, 0xaa, 0xaa}}); r != "" { + t.Fatal(r) + } + } + dnsServer.Shutdown() { diff --git a/common/strmatcher/matchers.go b/common/strmatcher/matchers.go index 188343401..7e073764c 100644 --- a/common/strmatcher/matchers.go +++ b/common/strmatcher/matchers.go @@ -176,7 +176,7 @@ func ToDomain(pattern string) (string, error) { } if !isASCII { var err error - pattern, err = idna.New().ToASCII(pattern) + pattern, err = idna.Punycode.ToASCII(pattern) if err != nil { return "", err }