validateID checks if the supplied container ID is valid, returning the ErrInvalidID in case it is not. The format of valid ID was never formally defined, instead the code was modified to allow or disallow specific characters. Currently, a valid ID is a non-empty string consisting only of the follo
(id string)
| 190 | // (such as . or ..) are rejected. |
| 191 | |
| 192 | func validateID(id string) error { |
| 193 | if len(id) < 1 { |
| 194 | return ErrInvalidID |
| 195 | } |
| 196 | |
| 197 | // Allowed characters: 0-9 A-Z a-z _ + - . |
| 198 | for i := range len(id) { |
| 199 | c := id[i] |
| 200 | switch { |
| 201 | case c >= 'a' && c <= 'z': |
| 202 | case c >= 'A' && c <= 'Z': |
| 203 | case c >= '0' && c <= '9': |
| 204 | case c == '_': |
| 205 | case c == '+': |
| 206 | case c == '-': |
| 207 | case c == '.': |
| 208 | default: |
| 209 | return ErrInvalidID |
| 210 | } |
| 211 | |
| 212 | } |
| 213 | |
| 214 | if string(os.PathSeparator)+id != pathrs.LexicallyCleanPath(string(os.PathSeparator)+id) { |
| 215 | return ErrInvalidID |
| 216 | } |
| 217 | |
| 218 | return nil |
| 219 | } |
no test coverage detected
searching dependent graphs…