// trailing dot to match pure Go reverse resolver and all other lookup
// routines.
// See golang.org/issue/12189.
+// But we don't want to add dots for local names from /etc/hosts.
+// It's hard to tell so we settle on the heuristic that names without dots
+// (like "localhost" or "myhost") do not get trailing dots, but any other
+// names do.
func absDomainName(b []byte) string {
- if len(b) > 0 && b[len(b)-1] != '.' {
+ hasDots := false
+ for _, x := range b {
+ if x == '.' {
+ hasDots = true
+ }
+ }
+ if hasDots && b[len(b)-1] != '.' {
b = append(b, '.')
}
return string(b)
t.Errorf("#%d: %v", i, err)
continue
}
+ mode := "netgo"
+ if i == 1 {
+ mode = "netcgo"
+ }
for _, name := range names {
- if !strings.HasSuffix(name, ".") {
- t.Errorf("#%d: got %s; want name ending with trailing dot", i, name)
+ if strings.Index(name, ".") == len(name)-1 { // "localhost" not "localhost."
+ t.Errorf("%s: got %s; want %s", mode, name, name[:len(name)-1])
+ } else if strings.Contains(name, ".") && !strings.HasSuffix(name, ".") { // "localhost.localdomain." not "localhost.localdomain"
+ t.Errorf("%s: got %s; want name ending with trailing dot", mode, name)
}
}
}