MCPcopy Create free account
hub / github.com/docker/cli / isValidName

Function isValidName

cli/context/store/store.go:238–252  ·  view source on GitHub ↗

isValidName checks if the context-name is valid ("^[a-zA-Z0-9][a-zA-Z0-9_.+-]+$"). Names must start with an alphanumeric character (a-zA-Z0-9), followed by alphanumeric or separators ("_", ".", "+", "-").

(s string)

Source from the content-addressed store, hash-verified

236// Names must start with an alphanumeric character (a-zA-Z0-9), followed by
237// alphanumeric or separators ("_", ".", "+", "-").
238func isValidName(s string) bool {
239 if len(s) < 2 || !isAlphaNum(s[0]) {
240 return false
241 }
242
243 for i := 1; i < len(s); i++ {
244 c := s[i]
245 if isAlphaNum(c) || c == '_' || c == '.' || c == '+' || c == '-' {
246 continue
247 }
248 return false
249 }
250
251 return true
252}
253
254func isAlphaNum(c byte) bool {
255 return (c >= 'a' && c <= 'z') ||

Callers 1

ValidateContextNameFunction · 0.85

Calls 1

isAlphaNumFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…