Expose DomainRegexp from reference

This fix is based on:
https://github.com/docker/docker/pull/30746#discussion_r99650885

The goal is to reuse the `DomainRegexp` in docker to check
for `<host>:<port>` pattern.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang 2017-02-07 17:43:28 -08:00
parent b1993c9530
commit 95daa793b8
2 changed files with 6 additions and 6 deletions

View file

@ -20,15 +20,15 @@ var (
optional(repeated(separatorRegexp, alphaNumericRegexp))) optional(repeated(separatorRegexp, alphaNumericRegexp)))
// domainComponentRegexp restricts the registry domain component of a // domainComponentRegexp restricts the registry domain component of a
// repository name to start with a component as defined by domainRegexp // repository name to start with a component as defined by DomainRegexp
// and followed by an optional port. // and followed by an optional port.
domainComponentRegexp = match(`(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])`) domainComponentRegexp = match(`(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])`)
// domainRegexp defines the structure of potential domain components // DomainRegexp defines the structure of potential domain components
// that may be part of image names. This is purposely a subset of what is // 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 // allowed by DNS to ensure backwards compatibility with Docker image
// names. // names.
domainRegexp = expression( DomainRegexp = expression(
domainComponentRegexp, domainComponentRegexp,
optional(repeated(literal(`.`), domainComponentRegexp)), optional(repeated(literal(`.`), domainComponentRegexp)),
optional(literal(`:`), match(`[0-9]+`))) optional(literal(`:`), match(`[0-9]+`)))
@ -51,14 +51,14 @@ var (
// regexp has capturing groups for the domain and name part omitting // regexp has capturing groups for the domain and name part omitting
// the separating forward slash from either. // the separating forward slash from either.
NameRegexp = expression( NameRegexp = expression(
optional(domainRegexp, literal(`/`)), optional(DomainRegexp, literal(`/`)),
nameComponentRegexp, nameComponentRegexp,
optional(repeated(literal(`/`), nameComponentRegexp))) optional(repeated(literal(`/`), nameComponentRegexp)))
// anchoredNameRegexp is used to parse a name value, capturing the // anchoredNameRegexp is used to parse a name value, capturing the
// domain and trailing components. // domain and trailing components.
anchoredNameRegexp = anchored( anchoredNameRegexp = anchored(
optional(capture(domainRegexp), literal(`/`)), optional(capture(DomainRegexp), literal(`/`)),
capture(nameComponentRegexp, capture(nameComponentRegexp,
optional(repeated(literal(`/`), nameComponentRegexp)))) optional(repeated(literal(`/`), nameComponentRegexp))))

View file

@ -116,7 +116,7 @@ func TestDomainRegexp(t *testing.T) {
match: true, match: true,
}, },
} }
r := regexp.MustCompile(`^` + domainRegexp.String() + `$`) r := regexp.MustCompile(`^` + DomainRegexp.String() + `$`)
for i := range hostcases { for i := range hostcases {
checkRegexp(t, r, hostcases[i]) checkRegexp(t, r, hostcases[i])
} }