-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fixes: no name check in docker container command #1331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/docker/cli/cli/names" | ||
| ) | ||
|
|
||
| var ( | ||
| validContainerNamePattern = names.RestrictedNamePattern | ||
|
lifubang marked this conversation as resolved.
Outdated
|
||
| ) | ||
|
|
||
| // CheckContainerName check container's name is valid or not | ||
| func CheckContainerName(name string) bool { | ||
| if len(name) == 0 { | ||
|
lifubang marked this conversation as resolved.
Outdated
|
||
| return false | ||
| } | ||
| return validContainerNamePattern.MatchString(strings.TrimPrefix(name, "/")) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why trimming the prefix? Is a container "/aaaa" valid? @thaJeztah WDYT?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, docker daemon said it's valid.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the leading slash is automatically added, and for historic reasons; a container is named
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it's allowed to manually create a container with a slash though; they should be added automatically by the daemon where needed |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package names | ||
|
|
||
| import ( | ||
| "regexp" | ||
| ) | ||
|
|
||
| // RestrictedNameChars collects the characters allowed to represent a name, normally used to validate container and volume names. | ||
| const RestrictedNameChars = `[a-zA-Z0-9][a-zA-Z0-9_.-]` | ||
|
lifubang marked this conversation as resolved.
Outdated
|
||
|
|
||
| // RestrictedNamePattern is a regular expression to validate names against the collection of restricted characters. | ||
| var RestrictedNamePattern = regexp.MustCompile(`^` + RestrictedNameChars + `+$`) | ||
|
lifubang marked this conversation as resolved.
Outdated
|
||
Uh oh!
There was an error while loading. Please reload this page.