|
|
|
@ -229,7 +229,7 @@ type (
|
|
|
|
|
|
|
|
|
|
|
|
// hostRegex is a pretty naive regex for validating host urls. The goal of it is not to ultimately validate all possible valid hosts,
|
|
|
|
// hostRegex is a pretty naive regex for validating host urls. The goal of it is not to ultimately validate all possible valid hosts,
|
|
|
|
// but to catch common user errors such as including a scheme or path in the host string.
|
|
|
|
// but to catch common user errors such as including a scheme or path in the host string.
|
|
|
|
var hostRegex = regexp.MustCompile(`^(?P<scheme>[a-z]*:\/\/)?(?P<host>[a-zA-Z0-9-\.\:]+)(?P<path>\/.*)?$`)
|
|
|
|
var hostRegex = regexp.MustCompile(`^(?P<scheme>[a-zA-Z][a-zA-Z0-9+\-.]*:\/\/)?(?P<host>[a-zA-Z0-9\-._:\[\]]+)(?P<path>\/.*)?$`)
|
|
|
|
|
|
|
|
|
|
|
|
// validateHost checks that the host matches some required pre-checks e.g. does not contain a scheme or path.
|
|
|
|
// validateHost checks that the host matches some required pre-checks e.g. does not contain a scheme or path.
|
|
|
|
// While ORAS will also validate some of these things, the current errors are a bit opaque.
|
|
|
|
// While ORAS will also validate some of these things, the current errors are a bit opaque.
|
|
|
|
@ -240,8 +240,8 @@ func validateHost(host string) error {
|
|
|
|
return fmt.Errorf("invalid host: %q", host)
|
|
|
|
return fmt.Errorf("invalid host: %q", host)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
scheme := matches[1]
|
|
|
|
scheme := matches[hostRegex.SubexpIndex("scheme")]
|
|
|
|
path := matches[3]
|
|
|
|
path := matches[hostRegex.SubexpIndex("path")]
|
|
|
|
|
|
|
|
|
|
|
|
if scheme != "" {
|
|
|
|
if scheme != "" {
|
|
|
|
return fmt.Errorf("host should not contain a scheme (e.g. http://), found %q", scheme)
|
|
|
|
return fmt.Errorf("host should not contain a scheme (e.g. http://), found %q", scheme)
|
|
|
|
|