From 7e8ec44078529353c18c8fe34e5207014ce1e685 Mon Sep 17 00:00:00 2001 From: Mateusz Poliwczak Date: Fri, 21 Jul 2023 08:11:49 +0200 Subject: [PATCH] fixes Change-Id: Iddb64848b66578cb68bfa1f724f5b56bfe903316 --- src/net/dnsclient_unix.go | 4 ++-- src/net/dnsclient_unix_test.go | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/net/dnsclient_unix.go b/src/net/dnsclient_unix.go index 003f5f0b183..2428c2700a4 100644 --- a/src/net/dnsclient_unix.go +++ b/src/net/dnsclient_unix.go @@ -501,7 +501,7 @@ func (conf *dnsConfig) nameList(name string) []string { // Build list of search choices. names := make([]string, 0, 1+len(conf.search)) // If name has enough dots, try unsuffixed first. - if !avoidDNS(name) && hasNdots { + if hasNdots && !avoidDNS(name) { names = append(names, name) } // Try suffixes that are not too long (see isDomainName). @@ -512,7 +512,7 @@ func (conf *dnsConfig) nameList(name string) []string { } } // Try unsuffixed, if not tried first above. - if !avoidDNS(name) && !hasNdots { + if !hasNdots && !avoidDNS(name) { names = append(names, name) } return names diff --git a/src/net/dnsclient_unix_test.go b/src/net/dnsclient_unix_test.go index 55d4bcb19e2..e842b41155a 100644 --- a/src/net/dnsclient_unix_test.go +++ b/src/net/dnsclient_unix_test.go @@ -16,14 +16,13 @@ import ( "path/filepath" "reflect" "runtime" + "slices" "strings" "sync" "sync/atomic" "testing" "time" - "slices" - "golang.org/x/net/dns/dnsmessage" ) @@ -197,12 +196,12 @@ func TestNameListAvoidDNS(t *testing.T) { c := &dnsConfig{search: []string{"go.dev.", "onion."}} got := c.nameList("www") if !slices.Equal(got, []string{"www.", "www.go.dev."}) { - t.Fatalf("nameList(\"www\") = %v, want \"www\", \"www.go.dev\"", got) + t.Fatalf(`nameList("www") = %v, want "www.", "www.go.dev."`, got) } got = c.nameList("www.onion") if !slices.Equal(got, []string{"www.onion.go.dev."}) { - t.Fatalf("nameList(\"www.onion\") = %v, want \"www.onion.go.dev\"", got) + t.Fatalf(`nameList("www.onion") = %v, want "www.onion.go.dev."`, got) } }