From a4cec8ca82ae277aaa412f4e55bbc013f6d0d8e4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 11 Nov 2022 13:00:28 +0100 Subject: [PATCH] reference: introduce const for "localhost" Localhost is treated special when parsing references, and always considered to be a domain, despite not having a "." nor a ":port". Adding a const for this, to allow documenting this special case (making it more visible). Signed-off-by: Sebastiaan van Stijn --- reference/normalize.go | 2 +- reference/regexp.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/reference/normalize.go b/reference/normalize.go index 43170e6f..f2ce13ad 100644 --- a/reference/normalize.go +++ b/reference/normalize.go @@ -125,7 +125,7 @@ func ParseDockerRef(ref string) (Named, error) { // needs to be already validated before. func splitDockerDomain(name string) (domain, remainder string) { i := strings.IndexRune(name, '/') - if i == -1 || (!strings.ContainsAny(name[:i], ".:") && name[:i] != "localhost" && strings.ToLower(name[:i]) == name[:i]) { + if i == -1 || (!strings.ContainsAny(name[:i], ".:") && name[:i] != localhost && strings.ToLower(name[:i]) == name[:i]) { domain, remainder = defaultDomain, name } else { domain, remainder = name[:i], name[i+1:] diff --git a/reference/regexp.go b/reference/regexp.go index 2974b1eb..cb8a048f 100644 --- a/reference/regexp.go +++ b/reference/regexp.go @@ -19,6 +19,10 @@ const ( // supported names. separator = `(?:[._]|__|[-]*)` + // localhost is treated as a special value for domain-name. Any other + // domain-name without a "." or a ":port" are considered a path component. + localhost = `localhost` + // domainNameComponent restricts the registry domain component of a // repository name to start with a component as defined by DomainRegexp. domainNameComponent = `(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])`