Allow uppercase characters in hostnames

This allows hostnames to contain uppercase characters, matching behavior
in Docker versions before 1.10. It does not attempt to canonicalize
hostnames into a lowercase format before parsing, since this could lead
to corner cases (for example, making Hostname.Domain.Com/ref ambiguous
on a daemon which contains references for both hostname.domain.com/ref
and Hostname.Domain.Com/ref).

Fixes: #1433

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
Aaron Lehmann 2016-02-05 16:00:12 -08:00 committed by Richard Scothern
parent 0996228761
commit 34c3acf8a8
3 changed files with 14 additions and 2 deletions

View file

@ -6,7 +6,7 @@
// reference := repository [ ":" tag ] [ "@" digest ] // reference := repository [ ":" tag ] [ "@" digest ]
// name := [hostname '/'] component ['/' component]* // name := [hostname '/'] component ['/' component]*
// hostname := hostcomponent ['.' hostcomponent]* [':' port-number] // hostname := hostcomponent ['.' hostcomponent]* [':' port-number]
// hostcomponent := /([a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])/ // hostcomponent := /([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])/
// port-number := /[0-9]+/ // port-number := /[0-9]+/
// component := alpha-numeric [separator alpha-numeric]* // component := alpha-numeric [separator alpha-numeric]*
// alpha-numeric := /[a-z0-9]+/ // alpha-numeric := /[a-z0-9]+/

View file

@ -22,7 +22,7 @@ var (
// hostnameComponentRegexp restricts the registry hostname component of a // hostnameComponentRegexp restricts the registry hostname component of a
// repository name to start with a component as defined by hostnameRegexp // repository name to start with a component as defined by hostnameRegexp
// and followed by an optional port. // and followed by an optional port.
hostnameComponentRegexp = match(`(?:[a-z0-9]|[a-z0-9][a-z0-9-]*[a-z0-9])`) hostnameComponentRegexp = match(`(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])`)
// hostnameRegexp defines the structure of potential hostname components // hostnameRegexp defines the structure of potential hostname components
// that may be part of image names. This is purposely a subset of what is // that may be part of image names. This is purposely a subset of what is

View file

@ -111,6 +111,10 @@ func TestHostRegexp(t *testing.T) {
input: "xn--n3h.com", // ☃.com in punycode input: "xn--n3h.com", // ☃.com in punycode
match: true, match: true,
}, },
{
input: "Asdf.com", // uppercase character
match: true,
},
} }
r := regexp.MustCompile(`^` + hostnameRegexp.String() + `$`) r := regexp.MustCompile(`^` + hostnameRegexp.String() + `$`)
for i := range hostcases { for i := range hostcases {
@ -399,6 +403,14 @@ func TestFullNameRegexp(t *testing.T) {
match: true, match: true,
subs: []string{"registry.io", "foo/project--id.module--name.ver---sion--name"}, subs: []string{"registry.io", "foo/project--id.module--name.ver---sion--name"},
}, },
{
input: "Asdf.com/foo/bar", // uppercase character in hostname
match: true,
},
{
input: "Foo/FarB", // uppercase characters in remote name
match: false,
},
} }
for i := range testcases { for i := range testcases {
checkRegexp(t, anchoredNameRegexp, testcases[i]) checkRegexp(t, anchoredNameRegexp, testcases[i])