From b473f8adec7dab35614f0c20b0738a865830b443 Mon Sep 17 00:00:00 2001 From: Juned Memon Date: Sat, 9 May 2020 16:57:16 +0530 Subject: [PATCH] Fixes repo parsing Signed-off-by: Juned Memon --- internal/experimental/registry/reference.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/experimental/registry/reference.go b/internal/experimental/registry/reference.go index ced6cf33a..73c409ba2 100644 --- a/internal/experimental/registry/reference.go +++ b/internal/experimental/registry/reference.go @@ -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 }