mirror of
https://github.com/clearlinux/docker.git
synced 2026-08-19 12:16:30 +00:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -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