Allow single name component repository names

Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
Derek McGowan 2015-01-28 14:51:02 -08:00
parent 686da01dd7
commit 94309badec
3 changed files with 15 additions and 5 deletions

View file

@ -17,7 +17,7 @@ const (
// 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 = 2 RepositoryNameMinComponents = 1
// RepositoryNameMaxComponents is the maximum number of slash-delimited // RepositoryNameMaxComponents is the maximum number of slash-delimited
// components that a repository name must have // components that a repository name must have
@ -41,9 +41,9 @@ var RepositoryNameComponentAnchoredRegexp = regexp.MustCompile(`^` + RepositoryN
// Looking path prefixes and s3 limitation of 1024, this should likely be // Looking path prefixes and s3 limitation of 1024, this should likely be
// around 512 bytes. 256 bytes might be more manageable. // around 512 bytes. 256 bytes might be more manageable.
// RepositoryNameRegexp builds on RepositoryNameComponentRegexp to allow 2 to // RepositoryNameRegexp builds on RepositoryNameComponentRegexp to allow 1 to
// 5 path components, separated by a forward slash. // 5 path components, separated by a forward slash.
var RepositoryNameRegexp = regexp.MustCompile(`(?:` + RepositoryNameComponentRegexp.String() + `/){1,4}` + RepositoryNameComponentRegexp.String()) var RepositoryNameRegexp = regexp.MustCompile(`(?:` + RepositoryNameComponentRegexp.String() + `/){0,4}` + 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}`)

View file

@ -9,6 +9,9 @@ func TestRepositoryNameRegexp(t *testing.T) {
input string input string
err error err error
}{ }{
{
input: "short",
},
{ {
input: "simple/name", input: "simple/name",
}, },
@ -41,7 +44,6 @@ func TestRepositoryNameRegexp(t *testing.T) {
}, },
{ {
input: "asdf", input: "asdf",
err: ErrRepositoryNameMissingComponents,
}, },
{ {
input: "asdf$$^/aa", input: "asdf$$^/aa",
@ -58,7 +60,7 @@ func TestRepositoryNameRegexp(t *testing.T) {
}, },
{ {
input: "a", input: "a",
err: ErrRepositoryNameMissingComponents, err: ErrRepositoryNameComponentShort,
}, },
{ {
input: "a-/a/a/a", input: "a-/a/a/a",

View file

@ -51,6 +51,14 @@ func TestRouter(t *testing.T) {
RequestURI: "/v2/", RequestURI: "/v2/",
Vars: map[string]string{}, Vars: map[string]string{},
}, },
{
RouteName: RouteNameManifest,
RequestURI: "/v2/foo/manifests/bar",
Vars: map[string]string{
"name": "foo",
"tag": "bar",
},
},
{ {
RouteName: RouteNameManifest, RouteName: RouteNameManifest,
RequestURI: "/v2/foo/bar/manifests/tag", RequestURI: "/v2/foo/bar/manifests/tag",