Merge pull request #242 from ncdc/remove-max-component-length
Remove max repository component length restrictionmaster
						commit
						ddde6b4363
					
				|  | @ -15,35 +15,27 @@ const ( | ||||||
| 	// single repository name slash-delimited component
 | 	// single repository name slash-delimited component
 | ||||||
| 	RepositoryNameComponentMinLength = 2 | 	RepositoryNameComponentMinLength = 2 | ||||||
| 
 | 
 | ||||||
| 	// RepositoryNameComponentMaxLength is the maximum number of characters in a
 |  | ||||||
| 	// single repository name slash-delimited component
 |  | ||||||
| 	RepositoryNameComponentMaxLength = 30 |  | ||||||
| 
 |  | ||||||
| 	// RepositoryNameMinComponents is the minimum number of slash-delimited
 | 	// RepositoryNameMinComponents is the minimum number of slash-delimited
 | ||||||
| 	// components that a repository name must have
 | 	// components that a repository name must have
 | ||||||
| 	RepositoryNameMinComponents = 1 | 	RepositoryNameMinComponents = 1 | ||||||
| 
 | 
 | ||||||
| 	// RepositoryNameMaxComponents is the maximum number of slash-delimited
 |  | ||||||
| 	// components that a repository name must have
 |  | ||||||
| 	RepositoryNameMaxComponents = 5 |  | ||||||
| 
 |  | ||||||
| 	// RepositoryNameTotalLengthMax is the maximum total number of characters in
 | 	// RepositoryNameTotalLengthMax is the maximum total number of characters in
 | ||||||
| 	// a repository name
 | 	// a repository name
 | ||||||
| 	RepositoryNameTotalLengthMax = 255 | 	RepositoryNameTotalLengthMax = 255 | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| // RepositoryNameComponentRegexp restricts registtry path components names to
 | // RepositoryNameComponentRegexp restricts registry path component names to
 | ||||||
| // start with at least two letters or numbers, with following parts able to
 | // start with at least one letter or number, with following parts able to
 | ||||||
| // separated by one period, dash or underscore.
 | // be separated by one period, dash or underscore.
 | ||||||
| var RepositoryNameComponentRegexp = regexp.MustCompile(`[a-z0-9]+(?:[._-][a-z0-9]+)*`) | var RepositoryNameComponentRegexp = regexp.MustCompile(`[a-z0-9]+(?:[._-][a-z0-9]+)*`) | ||||||
| 
 | 
 | ||||||
| // RepositoryNameComponentAnchoredRegexp is the version of
 | // RepositoryNameComponentAnchoredRegexp is the version of
 | ||||||
| // RepositoryNameComponentRegexp which must completely match the content
 | // RepositoryNameComponentRegexp which must completely match the content
 | ||||||
| var RepositoryNameComponentAnchoredRegexp = regexp.MustCompile(`^` + RepositoryNameComponentRegexp.String() + `$`) | var RepositoryNameComponentAnchoredRegexp = regexp.MustCompile(`^` + RepositoryNameComponentRegexp.String() + `$`) | ||||||
| 
 | 
 | ||||||
| // RepositoryNameRegexp builds on RepositoryNameComponentRegexp to allow 1 to
 | // RepositoryNameRegexp builds on RepositoryNameComponentRegexp to allow
 | ||||||
| // 5 path components, separated by a forward slash.
 | // multiple path components, separated by a forward slash.
 | ||||||
| var RepositoryNameRegexp = regexp.MustCompile(`(?:` + RepositoryNameComponentRegexp.String() + `/){0,4}` + RepositoryNameComponentRegexp.String()) | var RepositoryNameRegexp = regexp.MustCompile(`(?:` + RepositoryNameComponentRegexp.String() + `/)*` + RepositoryNameComponentRegexp.String()) | ||||||
| 
 | 
 | ||||||
| // TagNameRegexp matches valid tag names. From docker/docker:graph/tags.go.
 | // TagNameRegexp matches valid tag names. From docker/docker:graph/tags.go.
 | ||||||
| var TagNameRegexp = regexp.MustCompile(`[\w][\w.-]{0,127}`) | var TagNameRegexp = regexp.MustCompile(`[\w][\w.-]{0,127}`) | ||||||
|  | @ -56,19 +48,10 @@ var ( | ||||||
| 	// RepositoryNameComponentMinLength
 | 	// RepositoryNameComponentMinLength
 | ||||||
| 	ErrRepositoryNameComponentShort = fmt.Errorf("respository name component must be %v or more characters", RepositoryNameComponentMinLength) | 	ErrRepositoryNameComponentShort = fmt.Errorf("respository name component must be %v or more characters", RepositoryNameComponentMinLength) | ||||||
| 
 | 
 | ||||||
| 	// ErrRepositoryNameComponentLong is returned when a repository name
 |  | ||||||
| 	// contains a component which is longer than
 |  | ||||||
| 	// RepositoryNameComponentMaxLength
 |  | ||||||
| 	ErrRepositoryNameComponentLong = fmt.Errorf("respository name component must be %v characters or less", RepositoryNameComponentMaxLength) |  | ||||||
| 
 |  | ||||||
| 	// ErrRepositoryNameMissingComponents is returned when a repository name
 | 	// ErrRepositoryNameMissingComponents is returned when a repository name
 | ||||||
| 	// contains fewer than RepositoryNameMinComponents components
 | 	// contains fewer than RepositoryNameMinComponents components
 | ||||||
| 	ErrRepositoryNameMissingComponents = fmt.Errorf("repository name must have at least %v components", RepositoryNameMinComponents) | 	ErrRepositoryNameMissingComponents = fmt.Errorf("repository name must have at least %v components", RepositoryNameMinComponents) | ||||||
| 
 | 
 | ||||||
| 	// ErrRepositoryNameTooManyComponents is returned when a repository name
 |  | ||||||
| 	// contains more than RepositoryNameMaxComponents components
 |  | ||||||
| 	ErrRepositoryNameTooManyComponents = fmt.Errorf("repository name %v or less components", RepositoryNameMaxComponents) |  | ||||||
| 
 |  | ||||||
| 	// ErrRepositoryNameLong is returned when a repository name is longer than
 | 	// ErrRepositoryNameLong is returned when a repository name is longer than
 | ||||||
| 	// RepositoryNameTotalLengthMax
 | 	// RepositoryNameTotalLengthMax
 | ||||||
| 	ErrRepositoryNameLong = fmt.Errorf("repository name must not be more than %v characters", RepositoryNameTotalLengthMax) | 	ErrRepositoryNameLong = fmt.Errorf("repository name must not be more than %v characters", RepositoryNameTotalLengthMax) | ||||||
|  | @ -103,19 +86,11 @@ func ValidateRespositoryName(name string) error { | ||||||
| 		return ErrRepositoryNameMissingComponents | 		return ErrRepositoryNameMissingComponents | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if len(components) > RepositoryNameMaxComponents { |  | ||||||
| 		return ErrRepositoryNameTooManyComponents |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	for _, component := range components { | 	for _, component := range components { | ||||||
| 		if len(component) < RepositoryNameComponentMinLength { | 		if len(component) < RepositoryNameComponentMinLength { | ||||||
| 			return ErrRepositoryNameComponentShort | 			return ErrRepositoryNameComponentShort | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if len(component) > RepositoryNameComponentMaxLength { |  | ||||||
| 			return ErrRepositoryNameComponentLong |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		if !RepositoryNameComponentAnchoredRegexp.MatchString(component) { | 		if !RepositoryNameComponentAnchoredRegexp.MatchString(component) { | ||||||
| 			return ErrRepositoryNameComponentInvalid | 			return ErrRepositoryNameComponentInvalid | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| package v2 | package v2 | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"strings" | ||||||
| 	"testing" | 	"testing" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | @ -23,7 +24,6 @@ func TestRepositoryNameRegexp(t *testing.T) { | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "aa/aa/aa/aa/aa/aa/aa/aa/aa/bb/bb/bb/bb/bb/bb", | 			input: "aa/aa/aa/aa/aa/aa/aa/aa/aa/bb/bb/bb/bb/bb/bb", | ||||||
| 			err:   ErrRepositoryNameTooManyComponents, |  | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			input: "aa/aa/bb/bb/bb", | 			input: "aa/aa/bb/bb/bb", | ||||||
|  | @ -66,6 +66,13 @@ func TestRepositoryNameRegexp(t *testing.T) { | ||||||
| 			input: "a-/a/a/a", | 			input: "a-/a/a/a", | ||||||
| 			err:   ErrRepositoryNameComponentInvalid, | 			err:   ErrRepositoryNameComponentInvalid, | ||||||
| 		}, | 		}, | ||||||
|  | 		{ | ||||||
|  | 			input: strings.Repeat("a", 255), | ||||||
|  | 		}, | ||||||
|  | 		{ | ||||||
|  | 			input: strings.Repeat("a", 256), | ||||||
|  | 			err:   ErrRepositoryNameLong, | ||||||
|  | 		}, | ||||||
| 	} { | 	} { | ||||||
| 
 | 
 | ||||||
| 		failf := func(format string, v ...interface{}) { | 		failf := func(format string, v ...interface{}) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue