Merge pull request #8014 from jfrazelle/8012-prevent-container-names-starting-dash

Ensure container names start with a-zA-Z0-9
This commit is contained in:
unclejack 2014-09-12 23:15:16 +03:00
commit da4dba2e8c
2 changed files with 18 additions and 1 deletions

View File

@ -178,3 +178,20 @@ func TestGetFullName(t *testing.T) {
t.Fatal("Error should not be nil")
}
}
func TestValidContainerNames(t *testing.T) {
invalidNames := []string{"-rm", "&sdfsfd", "safd%sd"}
validNames := []string{"word-word", "word_word", "1weoid"}
for _, name := range invalidNames {
if validContainerNamePattern.MatchString(name) {
t.Fatalf("%q is not a valid container name and was returned as valid.", name)
}
}
for _, name := range validNames {
if !validContainerNamePattern.MatchString(name) {
t.Fatalf("%q is a valid container name and was returned as invalid.", name)
}
}
}

View File

@ -42,7 +42,7 @@ import (
var (
DefaultDns = []string{"8.8.8.8", "8.8.4.4"}
validContainerNameChars = `[a-zA-Z0-9_.-]`
validContainerNameChars = `[a-zA-Z0-9][a-zA-Z0-9_.-]`
validContainerNamePattern = regexp.MustCompile(`^/?` + validContainerNameChars + `+$`)
)