MCPcopy Create free account
hub / github.com/docker/secrets-engine / validIdentifier

Function validIdentifier

x/secrets/identifiers.go:36–60  ·  view source on GitHub ↗

validIdentifier checks if an identifier is valid without using regexp or unicode. Rules: - Components separated by '/' - Each component is non-empty - Only characters A-Z, a-z, 0-9, '.', '_', '-' or ':' - No leading, trailing, or double slashes

(s string)

Source from the content-addressed store, hash-verified

34// - Only characters A-Z, a-z, 0-9, '.', '_', '-' or ':'
35// - No leading, trailing, or double slashes
36func validIdentifier(s string) bool {
37 if len(s) == 0 {
38 return false
39 }
40
41 componentLen := 0
42
43 for _, r := range s {
44 switch {
45 case r == '/':
46 if componentLen == 0 {
47 // Empty component (leading, trailing, or double slash)
48 return false
49 }
50 componentLen = 0
51 case isValidRune(r):
52 componentLen++
53 default:
54 return false
55 }
56 }
57
58 // Final component must not be empty
59 return componentLen > 0
60}
61
62func isValidRune(c rune) bool {
63 return (c >= 'A' && c <= 'Z') ||

Callers 1

validFunction · 0.85

Calls 1

isValidRuneFunction · 0.85

Tested by

no test coverage detected