net: don't reject domain names with only numbers and hyphens
From https://github.com/golang/go/issues/17659#issuecomment-423113606 ...
> In kubernetes , isDomainName reject Pods "A Record" "pod-ip-address",
> for example: "172-17-0-16", as RFC 3696 section 2 requires
> "top-level domain names not be all-numeric", but this example has
> three hyphen, so I think it should not be reject.
Updates #17659
Change-Id: Ibd8ffb9473d69c45c91525953c09c6749233ca20
Reviewed-on: https://go-review.googlesource.com/136900
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Gudger <igudger@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
diff --git a/src/net/dnsclient.go b/src/net/dnsclient.go
index e352428..2c47bc4 100644
--- a/src/net/dnsclient.go
+++ b/src/net/dnsclient.go
@@ -75,7 +75,7 @@
}
last := byte('.')
- ok := false // Ok once we've seen a letter.
+ nonNumeric := false // true once we've seen a letter or hyphen
partlen := 0
for i := 0; i < len(s); i++ {
c := s[i]
@@ -83,7 +83,7 @@
default:
return false
case 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_':
- ok = true
+ nonNumeric = true
partlen++
case '0' <= c && c <= '9':
// fine
@@ -94,6 +94,7 @@
return false
}
partlen++
+ nonNumeric = true
case c == '.':
// Byte before dot cannot be dot, dash.
if last == '.' || last == '-' {
@@ -110,7 +111,7 @@
return false
}
- return ok
+ return nonNumeric
}
// absDomainName returns an absolute domain name which ends with a
diff --git a/src/net/dnsname_test.go b/src/net/dnsname_test.go
index 806d875..2964982 100644
--- a/src/net/dnsname_test.go
+++ b/src/net/dnsname_test.go
@@ -22,6 +22,7 @@
{"foo.com", true},
{"1foo.com", true},
{"26.0.0.73.com", true},
+ {"10-0-0-1", true},
{"fo-o.com", true},
{"fo1o.com", true},
{"foo1.com", true},