Skip to content

Commit 5f59458

Browse files
chore(controlplane): precompile version validation regex
Signed-off-by: Matías Insaurralde <matias@chainloop.dev>
1 parent c266e07 commit 5f59458

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

  • app/controlplane/pkg/biz

app/controlplane/pkg/biz/biz.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ var ProviderSet = wire.NewSet(
6464
wire.Struct(new(NewUserUseCaseParams), "*"),
6565
)
6666

67+
var (
68+
// versionRegexp allows alphanumeric, dots, hyphens, underscores, plus signs, and build metadata
69+
versionRegexp = regexp.MustCompile(`^[a-zA-Z0-9.\-_+]+(?:\+[a-zA-Z0-9.\-_]+)?$`)
70+
)
71+
6772
// IdentityReference represents a reference to an identity, which can be any entity in the system.
6873
type IdentityReference struct {
6974
// ID is the unique identifier of the identity
@@ -111,9 +116,7 @@ func ValidateIsDNS1123(name string) error {
111116
// The version string must match the following regular expression: ^[a-zA-Z0-9.\-]+$
112117
// This ensures the version only contains alphanumeric characters, dots, and hyphens.
113118
func ValidateVersion(version string) error {
114-
// Basic regex check (example: allow alphanumeric, dots, hyphens, underscores, plus signs, and build metadata)
115-
regex := regexp.MustCompile(`^[a-zA-Z0-9.\-_+]+(?:\+[a-zA-Z0-9.\-_]+)?$`)
116-
if !regex.MatchString(version) {
119+
if !versionRegexp.MatchString(version) {
117120
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))
118121
}
119122

0 commit comments

Comments
 (0)