MCPcopy
hub / github.com/containerd/containerd / Validate

Function Validate

pkg/identifiers/validate.go:52–65  ·  view source on GitHub ↗

Validate returns nil if the string s is a valid identifier. identifiers are similar to the domain name rules according to RFC 1035, section 2.3.1. However rules in this package are relaxed to allow numerals to follow period (".") and mixed case is allowed. In general identifiers that pass this val

(s string)

Source from the content-addressed store, hash-verified

50//
51// In general identifiers that pass this validation should be safe for use as filesystem path components.
52func Validate(s string) error {
53 if len(s) == 0 {
54 return fmt.Errorf("identifier must not be empty: %w", errdefs.ErrInvalidArgument)
55 }
56
57 if len(s) > maxLength {
58 return fmt.Errorf("identifier %q greater than maximum length (%d characters): %w", s, maxLength, errdefs.ErrInvalidArgument)
59 }
60
61 if !identifierRe.MatchString(s) {
62 return fmt.Errorf("identifier %q must match %v: %w", s, identifierRe, errdefs.ErrInvalidArgument)
63 }
64 return nil
65}
66
67func reGroup(s string) string {
68 return `(?:` + s + `)`

Callers 10

validateMethod · 0.92
validateContainerFunction · 0.92
CreateMethod · 0.92
validateTopicFunction · 0.92
validateEnvelopeFunction · 0.92
NewBundleFunction · 0.92
ExecMethod · 0.92
NamespaceRequiredFunction · 0.92
TestValidIdentifiersFunction · 0.70
TestInvalidIdentifiersFunction · 0.70

Calls 1

MatchStringMethod · 0.80

Tested by 2

TestValidIdentifiersFunction · 0.56
TestInvalidIdentifiersFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…