From 02e88c0f156bf7aa0e0a7b2508b1d2f3b1122b22 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 9 Nov 2022 18:27:05 +0100 Subject: [PATCH] reference: move exported regexes to separate block This makes them easier to find between the non-exported ones, and puts them as separate sections in the generated docs. While updating, also extended documentation for some to be more descriptive. Signed-off-by: Sebastiaan van Stijn --- reference/regexp.go | 64 +++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/reference/regexp.go b/reference/regexp.go index cb8a048ff..2af73840b 100644 --- a/reference/regexp.go +++ b/reference/regexp.go @@ -5,6 +5,39 @@ import ( "strings" ) +// DigestRegexp matches well-formed digests, including algorithm (e.g. "sha256:"). +var DigestRegexp = regexp.MustCompile(digestPat) + +// DomainRegexp matches hostname or IP-addresses, optionally including a port +// number. It defines the structure of potential domain components that may be +// part of image names. This is purposely a subset of what is allowed by DNS to +// ensure backwards compatibility with Docker image names. It may be a subset of +// DNS domain name, an IPv4 address in decimal format, or an IPv6 address between +// square brackets (excluding zone identifiers as defined by [RFC 6874] or special +// addresses such as IPv4-Mapped). +// +// [RFC 6874]: https://www.rfc-editor.org/rfc/rfc6874. +var DomainRegexp = regexp.MustCompile(domainAndPort) + +// IdentifierRegexp is the format for string identifier used as a +// content addressable identifier using sha256. These identifiers +// are like digests without the algorithm, since sha256 is used. +var IdentifierRegexp = regexp.MustCompile(identifier) + +// NameRegexp is the format for the name component of references, including +// an optional domain and port, but without tag or digest suffix. +var NameRegexp = regexp.MustCompile(namePat) + +// ReferenceRegexp is the full supported format of a reference. The regexp +// is anchored and has capturing groups for name, tag, and digest +// components. +var ReferenceRegexp = regexp.MustCompile(referencePat) + +// TagRegexp matches valid tag names. From [docker/docker:graph/tags.go]. +// +// [docker/docker:graph/tags.go]: https://github.com/moby/moby/blob/v1.6.0/graph/tags.go#L26-L28 +var TagRegexp = regexp.MustCompile(tag) + const ( // alphanumeric defines the alphanumeric atom, typically a // component of names. This only allows lower case characters and digits. @@ -76,27 +109,10 @@ var ( // compatibility with Docker image names. domainAndPort = host + optionalPort - // DomainRegexp matches hostname or IP-addresses, optionally including a port - // number. It defines the structure of potential domain components that may be - // part of image names. This is purposely a subset of what is allowed by DNS to - // ensure backwards compatibility with Docker image names. It may be a subset of - // DNS domain name, an IPv4 address in decimal format, or an IPv6 address between - // square brackets (excluding zone identifiers as defined by [rfc6874] or special - // addresses such as IPv4-Mapped). - // - // [rfc6874]: https://www.rfc-editor.org/rfc/rfc6874. - DomainRegexp = regexp.MustCompile(domainAndPort) - - // TagRegexp matches valid tag names. From docker/docker:graph/tags.go. - TagRegexp = regexp.MustCompile(tag) - // anchoredTagRegexp matches valid tag names, anchored at the start and // end of the matched string. anchoredTagRegexp = regexp.MustCompile(anchored(tag)) - // DigestRegexp matches well-formed digests, including algorithm (e.g. "sha256:"). - DigestRegexp = regexp.MustCompile(digestPat) - // anchoredDigestRegexp matches valid digests, anchored at the start and // end of the matched string. anchoredDigestRegexp = regexp.MustCompile(anchored(digestPat)) @@ -113,26 +129,12 @@ var ( remoteName = pathComponent + anyTimes(`/`+pathComponent) namePat = optional(domainAndPort+`/`) + remoteName - // NameRegexp is the format for the name component of references, including - // an optional domain and port, but without tag or digest suffix. - NameRegexp = regexp.MustCompile(namePat) - // anchoredNameRegexp is used to parse a name value, capturing the // domain and trailing components. anchoredNameRegexp = regexp.MustCompile(anchored(optional(capture(domainAndPort), `/`), capture(remoteName))) referencePat = anchored(capture(namePat), optional(`:`, capture(tag)), optional(`@`, capture(digestPat))) - // ReferenceRegexp is the full supported format of a reference. The regexp - // is anchored and has capturing groups for name, tag, and digest - // components. - ReferenceRegexp = regexp.MustCompile(referencePat) - - // IdentifierRegexp is the format for string identifier used as a - // content addressable identifier using sha256. These identifiers - // are like digests without the algorithm, since sha256 is used. - IdentifierRegexp = regexp.MustCompile(identifier) - // anchoredIdentifierRegexp is used to check or match an // identifier value, anchored at start and end of string. anchoredIdentifierRegexp = regexp.MustCompile(anchored(identifier))