Ensure container names start with a-zA-Z0-9
Closes #8012. Docker-DCO-1.1-Signed-off-by: Jessica Frazelle <jess@docker.com> (github: jfrazelle) Upstream-commit: aa2af817bee123827f4a857555db8fea5e01e7d7 Component: engine
This commit is contained in:
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 + `+$`)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user