From 5f594582b44898e289ea77a343ad3436e92d167a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Insaurralde?= Date: Tue, 24 Feb 2026 19:52:26 -0300 Subject: [PATCH] chore(controlplane): precompile version validation regex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Matías Insaurralde --- app/controlplane/pkg/biz/biz.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controlplane/pkg/biz/biz.go b/app/controlplane/pkg/biz/biz.go index 6e4a5ac85..1951c285a 100644 --- a/app/controlplane/pkg/biz/biz.go +++ b/app/controlplane/pkg/biz/biz.go @@ -64,6 +64,11 @@ var ProviderSet = wire.NewSet( wire.Struct(new(NewUserUseCaseParams), "*"), ) +var ( + // versionRegexp allows alphanumeric, dots, hyphens, underscores, plus signs, and build metadata + versionRegexp = regexp.MustCompile(`^[a-zA-Z0-9.\-_+]+(?:\+[a-zA-Z0-9.\-_]+)?$`) +) + // IdentityReference represents a reference to an identity, which can be any entity in the system. type IdentityReference struct { // ID is the unique identifier of the identity @@ -111,9 +116,7 @@ func ValidateIsDNS1123(name string) error { // The version string must match the following regular expression: ^[a-zA-Z0-9.\-]+$ // This ensures the version only contains alphanumeric characters, dots, and hyphens. func ValidateVersion(version string) error { - // Basic regex check (example: allow alphanumeric, dots, hyphens, underscores, plus signs, and build metadata) - regex := regexp.MustCompile(`^[a-zA-Z0-9.\-_+]+(?:\+[a-zA-Z0-9.\-_]+)?$`) - if !regex.MatchString(version) { + if !versionRegexp.MatchString(version) { return NewErrValidationStr(fmt.Sprintf("invalid version format: %s. Valid examples: '1.0.0', 'v2.1-alpha', '3.0.0+build.123', '2024.3.12', 'v1.0_beta'", version)) }