Go 1.12.8 introduced some breaking fixes (see 3226f2d492)
for a CVE. This broke the way we were doing registry reference parsing.
This removes the call to the containerd libraries in favor of our own
parsing and adds additional unit tests
Signed-off-by: Taylor Thomas <taylor.thomas@microsoft.com>
validPortRegEx=regexp.MustCompile(`^([1-9]\d{0,3}|0|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$`)// adapted from https://stackoverflow.com/a/12968117
errEmptyRepo=errors.New("parsed repo was empty")
errTooManyColons=errors.New("ref may only contain a single colon character (:) unless specifying a port number")
validPortRegEx=regexp.MustCompile(`^([1-9]\d{0,3}|0|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$`)// adapted from https://stackoverflow.com/a/12968117
// TODO: Currently we don't support digests, so we are only splitting on the
// colon. However, when we add support for digests, we'll need to use the
// regexp anyway to split on both colons and @, so leaving it like this for
// now
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")
)
type(
// Reference defines the main components of a reference specification
Referencestruct{
*reference.Spec
Tagstring
Repostring
}
@ -42,22 +45,34 @@ type (
// ParseReference converts a string to a Reference
funcParseReference(sstring)(*Reference,error){
spec,err:=reference.Parse(s)
iferr!=nil{
returnnil,err
ifs==""{
returnnil,errEmptyRepo
}
// Split the components of the string on the colon or @, if it is more than 3,
// immediately return an error. Other validation will be performed later in
// the function
splitComponents:=referenceDelimiter.Split(s,-1)
iflen(splitComponents)>3{
returnnil,errTooManyColons
}
// convert to our custom type and make necessary mods