forked from TrueCloudLab/distribution
Fix invalid tag name
Signed-off-by: Lei Jitang <leijitang@huawei.com>
This commit is contained in:
parent
eea521cfe4
commit
351babbf07
2 changed files with 9 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue