mirror of
https://github.com/golang/go
synced 2024-11-12 09:20:22 -07: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:
parent
4039be00a9
commit
5b3aafe2b5
@ -75,7 +75,7 @@ func isDomainName(s string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
last := byte('.')
|
last := byte('.')
|
||||||
ok := false // Ok once we've seen a letter.
|
nonNumeric := false // true once we've seen a letter or hyphen
|
||||||
partlen := 0
|
partlen := 0
|
||||||
for i := 0; i < len(s); i++ {
|
for i := 0; i < len(s); i++ {
|
||||||
c := s[i]
|
c := s[i]
|
||||||
@ -83,7 +83,7 @@ func isDomainName(s string) bool {
|
|||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
case 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_':
|
case 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_':
|
||||||
ok = true
|
nonNumeric = true
|
||||||
partlen++
|
partlen++
|
||||||
case '0' <= c && c <= '9':
|
case '0' <= c && c <= '9':
|
||||||
// fine
|
// fine
|
||||||
@ -94,6 +94,7 @@ func isDomainName(s string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
partlen++
|
partlen++
|
||||||
|
nonNumeric = true
|
||||||
case c == '.':
|
case c == '.':
|
||||||
// Byte before dot cannot be dot, dash.
|
// Byte before dot cannot be dot, dash.
|
||||||
if last == '.' || last == '-' {
|
if last == '.' || last == '-' {
|
||||||
@ -110,7 +111,7 @@ func isDomainName(s string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok
|
return nonNumeric
|
||||||
}
|
}
|
||||||
|
|
||||||
// absDomainName returns an absolute domain name which ends with a
|
// absDomainName returns an absolute domain name which ends with a
|
||||||
|
@ -22,6 +22,7 @@ var dnsNameTests = []dnsNameTest{
|
|||||||
{"foo.com", true},
|
{"foo.com", true},
|
||||||
{"1foo.com", true},
|
{"1foo.com", true},
|
||||||
{"26.0.0.73.com", true},
|
{"26.0.0.73.com", true},
|
||||||
|
{"10-0-0-1", true},
|
||||||
{"fo-o.com", true},
|
{"fo-o.com", true},
|
||||||
{"fo1o.com", true},
|
{"fo1o.com", true},
|
||||||
{"foo1.com", true},
|
{"foo1.com", true},
|
||||||
|
Loading…
Reference in New Issue
Block a user