(s string)
| 229 | } |
| 230 | |
| 231 | func validateHostPort(s string) error { |
| 232 | // Split host and port, and in case s can not be split, assume host only |
| 233 | host, port, err := net.SplitHostPort(s) |
| 234 | if err != nil { |
| 235 | host = s |
| 236 | port = "" |
| 237 | } |
| 238 | // If match against the `host:port` pattern fails, |
| 239 | // it might be `IPv6:port`, which will be captured by net.ParseIP(host) |
| 240 | if !validHostPortRegex().MatchString(s) && net.ParseIP(host) == nil { |
| 241 | return invalidParamf("invalid host %q", host) |
| 242 | } |
| 243 | if port != "" { |
| 244 | v, err := strconv.Atoi(port) |
| 245 | if err != nil { |
| 246 | return err |
| 247 | } |
| 248 | if v < 0 || v > 65535 { |
| 249 | return invalidParamf("invalid port %q", port) |
| 250 | } |
| 251 | } |
| 252 | return nil |
| 253 | } |
| 254 | |
| 255 | // NewIndexInfo creates a new [registry.IndexInfo] or the given |
| 256 | // repository-name, and detects whether the registry is considered |
no test coverage detected
searching dependent graphs…