diff options
author | Aaron Lehmann <aaron.lehmann@docker.com> | 2016-02-08 11:07:57 -0800 |
---|---|---|
committer | Aaron Lehmann <aaron.lehmann@docker.com> | 2016-02-10 14:03:41 -0800 |
commit | e2afab9c4a8be800dffee9b60b2197350987543c (patch) | |
tree | 5c47721b01e9b1088a94d011c8baef676bb550be /reference | |
parent | fa860c86ff0a368e686535c2689d1099fa9ea7a2 (diff) | |
download | docker-e2afab9c4a8be800dffee9b60b2197350987543c.tar.gz |
Allow uppercase characters in image reference hostname
This PR makes restores the pre-Docker 1.10 behavior of allowing
uppercase characters in registry hostnames.
Note that this only applies to hostnames, not remote image names.
Previous versions also prohibited uppercase letters after the hostname,
but Docker 1.10 extended this to the hostname itself.
- Vendor updated docker/distribution.
- Add a check to "normalize" that rejects remote names with uppercase
letters.
- Add test cases to TestTagValidPrefixedRepo and
TestTagInvalidUnprefixedRepo
Fixes: #20056
Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
Diffstat (limited to 'reference')
-rw-r--r-- | reference/reference.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/reference/reference.go b/reference/reference.go index 1e3482475f..e355596eab 100644 --- a/reference/reference.go +++ b/reference/reference.go @@ -1,6 +1,7 @@ package reference import ( + "errors" "fmt" "strings" @@ -72,7 +73,10 @@ func ParseNamed(s string) (Named, error) { // WithName returns a named object representing the given string. If the input // is invalid ErrReferenceInvalidFormat will be returned. func WithName(name string) (Named, error) { - name = normalize(name) + name, err := normalize(name) + if err != nil { + return nil, err + } if err := validateName(name); err != nil { return nil, err } @@ -172,15 +176,18 @@ func splitHostname(name string) (hostname, remoteName string) { // normalize returns a repository name in its normalized form, meaning it // will not contain default hostname nor library/ prefix for official images. -func normalize(name string) string { +func normalize(name string) (string, error) { host, remoteName := splitHostname(name) + if strings.ToLower(remoteName) != remoteName { + return "", errors.New("invalid reference format: repository name must be lowercase") + } if host == DefaultHostname { if strings.HasPrefix(remoteName, DefaultRepoPrefix) { - return strings.TrimPrefix(remoteName, DefaultRepoPrefix) + return strings.TrimPrefix(remoteName, DefaultRepoPrefix), nil } - return remoteName + return remoteName, nil } - return name + return name, nil } func validateName(name string) error { |