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

Function validPattern

x/secrets/pattern.go:34–61  ·  view source on GitHub ↗

validPattern checks if a pattern 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 - Asterisks rules: - '*' cannot be mixed with other characters

(s string)

Source from the content-addressed store, hash-verified

32// - '*' cannot be mixed with other characters in the same component
33// - there can be no more than two '*' per component
34func validPattern(s string) bool {
35 if len(s) == 0 {
36 return false
37 }
38
39 componentLen := 0
40 wildcardLen := 0
41
42 for _, r := range s {
43 switch {
44 case r == '/':
45 if !isValidComponentMatcher(componentLen, wildcardLen) {
46 return false
47 }
48 componentLen = 0
49 wildcardLen = 0
50 case isValidPatternRune(r):
51 componentLen++
52 if r == '*' {
53 wildcardLen++
54 }
55 default:
56 return false
57 }
58 }
59 // Final component
60 return isValidComponentMatcher(componentLen, wildcardLen)
61}
62
63func isValidComponentMatcher(componentLen, wildcardLen int) bool {
64 if wildcardLen > 2 {

Callers 2

ParsePatternFunction · 0.85
MustParsePatternFunction · 0.85

Calls 2

isValidComponentMatcherFunction · 0.85
isValidPatternRuneFunction · 0.85

Tested by

no test coverage detected