From 94309badec0d3164c199f9b03be6d73bdab18415 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Wed, 28 Jan 2015 14:51:02 -0800 Subject: [PATCH] Allow single name component repository names Signed-off-by: Derek McGowan (github: dmcgowan) --- api/v2/names.go | 6 +++--- api/v2/names_test.go | 6 ++++-- api/v2/routes_test.go | 8 ++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/api/v2/names.go b/api/v2/names.go index e0c05d48..d05eeb6a 100644 --- a/api/v2/names.go +++ b/api/v2/names.go @@ -17,7 +17,7 @@ const ( // RepositoryNameMinComponents is the minimum number of slash-delimited // components that a repository name must have - RepositoryNameMinComponents = 2 + RepositoryNameMinComponents = 1 // RepositoryNameMaxComponents is the maximum number of slash-delimited // 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 // 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. -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. var TagNameRegexp = regexp.MustCompile(`[\w][\w.-]{0,127}`) diff --git a/api/v2/names_test.go b/api/v2/names_test.go index 038386e4..69ba5305 100644 --- a/api/v2/names_test.go +++ b/api/v2/names_test.go @@ -9,6 +9,9 @@ func TestRepositoryNameRegexp(t *testing.T) { input string err error }{ + { + input: "short", + }, { input: "simple/name", }, @@ -41,7 +44,6 @@ func TestRepositoryNameRegexp(t *testing.T) { }, { input: "asdf", - err: ErrRepositoryNameMissingComponents, }, { input: "asdf$$^/aa", @@ -58,7 +60,7 @@ func TestRepositoryNameRegexp(t *testing.T) { }, { input: "a", - err: ErrRepositoryNameMissingComponents, + err: ErrRepositoryNameComponentShort, }, { input: "a-/a/a/a", diff --git a/api/v2/routes_test.go b/api/v2/routes_test.go index 29cd8106..af424616 100644 --- a/api/v2/routes_test.go +++ b/api/v2/routes_test.go @@ -51,6 +51,14 @@ func TestRouter(t *testing.T) { RequestURI: "/v2/", Vars: map[string]string{}, }, + { + RouteName: RouteNameManifest, + RequestURI: "/v2/foo/manifests/bar", + Vars: map[string]string{ + "name": "foo", + "tag": "bar", + }, + }, { RouteName: RouteNameManifest, RequestURI: "/v2/foo/bar/manifests/tag",