Skip to content

Commit f651a5d

Browse files
committed
registry: remove uses of lazyregexp
This package is imported by the CLI; implement a more basic approach. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent b33b4bd commit f651a5d

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ linters:
346346
path: "libnetwork/cmd/networkdb-test/dbclient"
347347
linters:
348348
- forbidigo
349+
- text: 'use of `regexp.MustCompile` forbidden'
350+
path: "registry/"
351+
linters:
352+
- forbidigo
349353

350354
# Log a warning if an exclusion rule is unused.
351355
# Default: false

registry/config.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
2+
//go:build go1.23
3+
14
package registry
25

36
import (
@@ -6,13 +9,14 @@ import (
69
"net/url"
710
"os"
811
"path/filepath"
12+
"regexp"
913
"runtime"
1014
"strconv"
1115
"strings"
16+
"sync"
1217

1318
"github.com/containerd/log"
1419
"github.com/distribution/reference"
15-
"github.com/docker/docker/internal/lazyregexp"
1620
"github.com/moby/moby/api/types/registry"
1721
)
1822

@@ -57,7 +61,9 @@ var (
5761
Host: DefaultRegistryHost,
5862
}
5963

60-
validHostPortRegex = lazyregexp.New(`^` + reference.DomainRegexp.String() + `$`)
64+
validHostPortRegex = sync.OnceValue(func() *regexp.Regexp {
65+
return regexp.MustCompile(`^` + reference.DomainRegexp.String() + `$`)
66+
})
6167
)
6268

6369
// runningWithRootlessKit is a fork of [rootless.RunningWithRootlessKit],
@@ -334,7 +340,7 @@ func validateHostPort(s string) error {
334340
}
335341
// If match against the `host:port` pattern fails,
336342
// it might be `IPv6:port`, which will be captured by net.ParseIP(host)
337-
if !validHostPortRegex.MatchString(s) && net.ParseIP(host) == nil {
343+
if !validHostPortRegex().MatchString(s) && net.ParseIP(host) == nil {
338344
return invalidParamf("invalid host %q", host)
339345
}
340346
if port != "" {

0 commit comments

Comments
 (0)