diff --git a/reference/normalize.go b/reference/normalize.go index da797b70..24f65e19 100644 --- a/reference/normalize.go +++ b/reference/normalize.go @@ -12,7 +12,7 @@ import ( var ( legacyDefaultDomain = "index.docker.io" defaultDomain = "docker.io" - defaultRepoPrefix = "library/" + officialRepoName = "library" defaultTag = "latest" ) @@ -70,7 +70,7 @@ func splitDockerDomain(name string) (domain, remainder string) { domain = defaultDomain } if domain == defaultDomain && !strings.ContainsRune(remainder, '/') { - remainder = defaultRepoPrefix + remainder + remainder = officialRepoName + "/" + remainder } return } @@ -89,7 +89,10 @@ func familiarizeName(named namedRepository) repository { if repo.domain == defaultDomain { repo.domain = "" - repo.path = strings.TrimPrefix(repo.path, defaultRepoPrefix) + // Handle official repositories which have the pattern "library/" + if split := strings.Split(repo.path, "/"); len(split) == 2 && split[0] == officialRepoName { + repo.path = split[1] + } } return repo } diff --git a/reference/normalize_test.go b/reference/normalize_test.go index 9697a36b..3284f885 100644 --- a/reference/normalize_test.go +++ b/reference/normalize_test.go @@ -208,6 +208,20 @@ func TestParseRepositoryInfo(t *testing.T) { AmbiguousName: "index.docker.io/library/ubuntu-12.04-base", Domain: "docker.io", }, + { + RemoteName: "library/foo/bar", + FamiliarName: "library/foo/bar", + FullName: "docker.io/library/foo/bar", + AmbiguousName: "", + Domain: "docker.io", + }, + { + RemoteName: "store/foo/bar", + FamiliarName: "store/foo/bar", + FullName: "docker.io/store/foo/bar", + AmbiguousName: "", + Domain: "docker.io", + }, } for _, tcase := range tcases { @@ -483,6 +497,21 @@ func TestNormalizedSplitHostname(t *testing.T) { domain: "xn--n3h.com:18080", name: "foo", }, + { + input: "docker.io/foo", + domain: "docker.io", + name: "library/foo", + }, + { + input: "docker.io/library/foo", + domain: "docker.io", + name: "library/foo", + }, + { + input: "docker.io/library/foo/bar", + domain: "docker.io", + name: "library/foo/bar", + }, } for _, testcase := range testcases { failf := func(format string, v ...interface{}) {