Fixes repo parsing

Signed-off-by: Juned Memon <junaid18183@gmail.com>
pull/8089/head
Juned Memon 5 years ago
parent af52d35fb6
commit b473f8adec
No known key found for this signature in database
GPG Key ID: B7C1868E3994DA9E

@ -34,6 +34,10 @@ var (
referenceDelimiter = regexp.MustCompile(`[:]`)
errEmptyRepo = errors.New("parsed repo was empty")
errTooManyColons = errors.New("ref may only contain a single colon character (:) unless specifying a port number")
// ErrInvalid is returned when there is an invalid reference
ErrInvalid = errors.New("invalid reference")
// ErrHostnameRequired is returned when the hostname is required
ErrHostnameRequired = errors.New("hostname required")
)
type (
@ -86,6 +90,7 @@ func (ref *Reference) FullName() string {
// validate makes sure the ref meets our criteria
func (ref *Reference) validate() error {
err := ref.validateRepo()
if err != nil {
return err
@ -100,7 +105,15 @@ func (ref *Reference) validateRepo() error {
}
// Makes sure the repo results in a parsable URL (similar to what is done
// with containerd reference parsing)
_, err := url.Parse(ref.Repo)
u, err := url.Parse("dummy://" + ref.Repo)
if u.Scheme != "dummy" {
return ErrInvalid
}
if u.Host == "" {
return ErrHostnameRequired
}
return err
}

Loading…
Cancel
Save