From 351babbf07f56082d65bca5a18ad7b39a881c8f1 Mon Sep 17 00:00:00 2001 From: Lei Jitang Date: Wed, 13 May 2015 14:23:13 +0800 Subject: [PATCH] Fix invalid tag name Signed-off-by: Lei Jitang --- docs/config.go | 6 ++++++ docs/registry_test.go | 3 +++ 2 files changed, 9 insertions(+) diff --git a/docs/config.go b/docs/config.go index a0a978cc..568756f4 100644 --- a/docs/config.go +++ b/docs/config.go @@ -198,6 +198,9 @@ func ValidateIndexName(val string) (string, error) { if val == "index."+IndexServerName() { val = IndexServerName() } + if strings.HasPrefix(val, "-") || strings.HasSuffix(val, "-") { + return "", fmt.Errorf("Invalid index name (%s). Cannot begin or end with a hyphen.", val) + } // *TODO: Check if valid hostname[:port]/ip[:port]? return val, nil } @@ -235,6 +238,9 @@ func validateRemoteName(remoteName string) error { if !validRepo.MatchString(name) { return fmt.Errorf("Invalid repository name (%s), only [a-z0-9-_.] are allowed", name) } + if strings.HasPrefix(name, "-") || strings.HasSuffix(name, "-") { + return fmt.Errorf("Invalid repository name (%s). Cannot begin or end with a hyphen.", name) + } return nil } diff --git a/docs/registry_test.go b/docs/registry_test.go index 3f63eb6e..799d080e 100644 --- a/docs/registry_test.go +++ b/docs/registry_test.go @@ -299,6 +299,9 @@ func TestValidateRepositoryName(t *testing.T) { invalidRepoNames := []string{ "https://github.com/docker/docker", "docker/Docker", + "-docker", + "-docker/docker", + "-docker.io/docker/docker", "docker///docker", "docker.io/docker/Docker", "docker.io/docker///docker",