Skip to content

Commit 727f80d

Browse files
authored
Merge pull request #22 from thaJeztah/more_consts
make more expressions a const
2 parents e3db434 + c577ba6 commit 727f80d

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

regexp.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,12 @@ const (
8989
// are allowed, IPv6 zone identifiers (rfc6874) or Special addresses such as
9090
// IPv4-Mapped are deliberately excluded.
9191
ipv6address = `\[(?:[a-fA-F0-9:]+)\]`
92-
)
9392

94-
var (
9593
// domainName defines the structure of potential domain components
9694
// that may be part of image names. This is purposely a subset of what is
9795
// allowed by DNS to ensure backwards compatibility with Docker image
9896
// names. This includes IPv4 addresses on decimal format.
99-
domainName = domainNameComponent + anyTimes(`\.`+domainNameComponent)
97+
domainName = domainNameComponent + `(?:\.` + domainNameComponent + `)*`
10098

10199
// host defines the structure of potential domains based on the URI
102100
// Host subcomponent on rfc3986. It may be a subset of DNS domain name,
@@ -108,7 +106,9 @@ var (
108106
// allowed by the URI Host subcomponent on rfc3986 to ensure backwards
109107
// compatibility with Docker image names.
110108
domainAndPort = host + optionalPort
109+
)
111110

111+
var (
112112
// anchoredTagRegexp matches valid tag names, anchored at the start and
113113
// end of the matched string.
114114
anchoredTagRegexp = regexp.MustCompile(anchored(tag))

regexp_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ func TestDomainRegexp(t *testing.T) {
161161
match: false,
162162
},
163163
}
164-
r := regexp.MustCompile(`^` + DomainRegexp.String() + `$`)
164+
r, err := regexp.Compile(`^` + domainAndPort + `$`)
165+
if err != nil {
166+
t.Fatal(err)
167+
}
165168
for _, tc := range tests {
166169
tc := tc
167170
t.Run(tc.input, func(t *testing.T) {

0 commit comments

Comments
 (0)