checkKey checks if the given value is a valid parameter key according to https://httpwg.org/specs/rfc9651.html#param.
(k string)
| 26 | // checkKey checks if the given value is a valid parameter key according to |
| 27 | // https://httpwg.org/specs/rfc9651.html#param. |
| 28 | func checkKey(k string) error { |
| 29 | if len(k) == 0 { |
| 30 | return fmt.Errorf("a key cannot be empty: %w", ErrInvalidKeyFormat) |
| 31 | } |
| 32 | |
| 33 | if !isLowerCaseAlpha(k[0]) && k[0] != '*' { |
| 34 | return fmt.Errorf("a key must start with a lower case alpha character or *: %w", ErrInvalidKeyFormat) |
| 35 | } |
| 36 | |
| 37 | for i := 1; i < len(k); i++ { |
| 38 | if !isKeyChar(k[i]) { |
| 39 | return fmt.Errorf("the character %c isn't allowed in a key: %w", k[i], ErrInvalidKeyFormat) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | return nil |
| 44 | } |
| 45 | |
| 46 | // marshalKey serializes as defined in |
| 47 | // https://httpwg.org/specs/rfc9651.html#ser-key. |
no test coverage detected
searching dependent graphs…