From aa21ff7efd262410735f32636bf33f72307e13cd Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 31 Aug 2022 19:19:23 +0200 Subject: [PATCH] store: move regex to where it's used Signed-off-by: Sebastiaan van Stijn --- store/store.go | 3 --- store/util.go | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/store/store.go b/store/store.go index 385b8d75..1ca650fc 100644 --- a/store/store.go +++ b/store/store.go @@ -4,7 +4,6 @@ import ( "encoding/json" "os" "path/filepath" - "regexp" "sort" "github.com/docker/docker/pkg/ioutils" @@ -199,8 +198,6 @@ type current struct { Global bool } -var namePattern = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9\.\-_]*$`) - func toHash(in string) string { return digest.FromBytes([]byte(in)).Hex()[:20] } diff --git a/store/util.go b/store/util.go index e8a4269a..278b64c3 100644 --- a/store/util.go +++ b/store/util.go @@ -2,12 +2,15 @@ package store import ( "os" + "regexp" "strings" "github.com/docker/docker/pkg/namesgenerator" "github.com/pkg/errors" ) +var namePattern = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9\.\-_]*$`) + func ValidateName(s string) (string, error) { if !namePattern.MatchString(s) { return "", errors.Errorf("invalid name %s, name needs to start with a letter and may not contain symbols, except ._-", s)