1
0
mirror of https://github.com/golang/go synced 2024-09-25 09:20:18 -06:00

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>
This commit is contained in:
Brad Fitzpatrick 2018-09-24 17:30:48 +00:00
parent 4039be00a9
commit 5b3aafe2b5
2 changed files with 5 additions and 3 deletions

View File

@ -75,7 +75,7 @@ func isDomainName(s string) bool {
}
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 @@ func isDomainName(s string) bool {
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 @@ func isDomainName(s string) bool {
return false
}
partlen++
nonNumeric = true
case c == '.':
// Byte before dot cannot be dot, dash.
if last == '.' || last == '-' {
@ -110,7 +111,7 @@ func isDomainName(s string) bool {
return false
}
return ok
return nonNumeric
}
// absDomainName returns an absolute domain name which ends with a

View File

@ -22,6 +22,7 @@ var dnsNameTests = []dnsNameTest{
{"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},