From bace767d2699988bbcf5cccc9bc39ae575bdd478 Mon Sep 17 00:00:00 2001 From: maicon Date: Wed, 1 Oct 2025 12:21:48 -0300 Subject: [PATCH] Unistore: Relax resource validation regex (#111885) Signed-off-by: Maicon Costa --- pkg/apimachinery/validation/validation.go | 4 ++-- pkg/apimachinery/validation/validation_test.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/apimachinery/validation/validation.go b/pkg/apimachinery/validation/validation.go index 4778db398f3..777eb59fa46 100644 --- a/pkg/apimachinery/validation/validation.go +++ b/pkg/apimachinery/validation/validation.go @@ -23,9 +23,9 @@ const qualifiedNameFmt string = "^(" + qnameCharFmt + qnameExtCharFmt + "*)?" + const qualifiedNameErrMsg string = "must consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character" const alphaCharFmt string = "[A-Za-z]" -const resourceCharFmt string = "[A-Za-z0-9]" // alpha numeric +const resourceCharFmt string = "[A-Za-z0-9-]" // alpha numeric plus dashes const resourceFmt string = "^" + alphaCharFmt + resourceCharFmt + "*$" -const resourceErrMsg string = "must consist of alphanumeric characters" +const resourceErrMsg string = "must consist of alphanumeric characters and dashes, and must start with an alphabetic character" var ( grafanaNameRegexp = regexp.MustCompile(grafanaNameFmt).MatchString diff --git a/pkg/apimachinery/validation/validation_test.go b/pkg/apimachinery/validation/validation_test.go index 2e699097cdd..3bb5fa61ad9 100644 --- a/pkg/apimachinery/validation/validation_test.go +++ b/pkg/apimachinery/validation/validation_test.go @@ -198,16 +198,17 @@ func TestValidation(t *testing.T) { "folders", "folders123", "aaa", + "hello-world", + "hello-world-", }, }, { name: "bad input", expect: []string{ - "resource must consist of alphanumeric characters (e.g. 'dashboards', or 'folders', regex used for validation is '^[A-Za-z][A-Za-z0-9]*$')", + "resource must consist of alphanumeric characters and dashes, and must start with an alphabetic character (e.g. 'dashboards', or 'folders', regex used for validation is '^[A-Za-z][A-Za-z0-9-]*$')", }, input: []string{ "_bad_input", "hello world", - "hello-world", "hello!", "hello~", "hello ",