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)
| 50 | // |
| 51 | // In general identifiers that pass this validation should be safe for use as filesystem path components. |
| 52 | func 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 | |
| 67 | func reGroup(s string) string { |
| 68 | return `(?:` + s + `)` |
searching dependent graphs…