Merge pull request #29523 from fraenkel/service_names_rfc1035
Automatic merge from submit-queue Allow service names up to 63 characters (RFC 1035) fixes #3752
This commit is contained in:
@@ -121,20 +121,20 @@ func IsDNS1123Subdomain(value string) []string {
|
||||
return errs
|
||||
}
|
||||
|
||||
const dns952LabelFmt string = "[a-z]([-a-z0-9]*[a-z0-9])?"
|
||||
const DNS952LabelMaxLength int = 24
|
||||
const dns1035LabelFmt string = "[a-z]([-a-z0-9]*[a-z0-9])?"
|
||||
const DNS1035LabelMaxLength int = 63
|
||||
|
||||
var dns952LabelRegexp = regexp.MustCompile("^" + dns952LabelFmt + "$")
|
||||
var dns1035LabelRegexp = regexp.MustCompile("^" + dns1035LabelFmt + "$")
|
||||
|
||||
// IsDNS952Label tests for a string that conforms to the definition of a label in
|
||||
// DNS (RFC 952).
|
||||
func IsDNS952Label(value string) []string {
|
||||
// IsDNS1035Label tests for a string that conforms to the definition of a label in
|
||||
// DNS (RFC 1035).
|
||||
func IsDNS1035Label(value string) []string {
|
||||
var errs []string
|
||||
if len(value) > DNS952LabelMaxLength {
|
||||
errs = append(errs, MaxLenError(DNS952LabelMaxLength))
|
||||
if len(value) > DNS1035LabelMaxLength {
|
||||
errs = append(errs, MaxLenError(DNS1035LabelMaxLength))
|
||||
}
|
||||
if !dns952LabelRegexp.MatchString(value) {
|
||||
errs = append(errs, RegexError(dns952LabelFmt, "my-name", "abc-123"))
|
||||
if !dns1035LabelRegexp.MatchString(value) {
|
||||
errs = append(errs, RegexError(dns1035LabelFmt, "my-name", "abc-123"))
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
@@ -86,13 +86,13 @@ func TestIsDNS1123Subdomain(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsDNS952Label(t *testing.T) {
|
||||
func TestIsDNS1035Label(t *testing.T) {
|
||||
goodValues := []string{
|
||||
"a", "ab", "abc", "a1", "a-1", "a--1--2--b",
|
||||
strings.Repeat("a", 24),
|
||||
strings.Repeat("a", 63),
|
||||
}
|
||||
for _, val := range goodValues {
|
||||
if msgs := IsDNS952Label(val); len(msgs) != 0 {
|
||||
if msgs := IsDNS1035Label(val); len(msgs) != 0 {
|
||||
t.Errorf("expected true for '%s': %v", val, msgs)
|
||||
}
|
||||
}
|
||||
@@ -104,10 +104,10 @@ func TestIsDNS952Label(t *testing.T) {
|
||||
"_", "a_", "_a", "a_b", "1_", "_1", "1_2",
|
||||
".", "a.", ".a", "a.b", "1.", ".1", "1.2",
|
||||
" ", "a ", " a", "a b", "1 ", " 1", "1 2",
|
||||
strings.Repeat("a", 25),
|
||||
strings.Repeat("a", 64),
|
||||
}
|
||||
for _, val := range badValues {
|
||||
if msgs := IsDNS952Label(val); len(msgs) == 0 {
|
||||
if msgs := IsDNS1035Label(val); len(msgs) == 0 {
|
||||
t.Errorf("expected false for '%s'", val)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user