1
0
mirror of https://github.com/golang/go synced 2024-11-26 18:16:48 -07:00
Change-Id: Iddb64848b66578cb68bfa1f724f5b56bfe903316
This commit is contained in:
Mateusz Poliwczak 2023-07-21 08:11:49 +02:00
parent e9b536d095
commit 7e8ec44078
2 changed files with 5 additions and 6 deletions

View File

@ -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

View File

@ -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)
}
}