regex to validate names following k8s validation rule
Signed-off-by: matteobarone <barmat90@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/catalog-model': minor
|
||||
---
|
||||
|
||||
Changed the regex to validate names following the Kubernetes validation rule, this allow to be more permissive validating the name of the object in Backstage.
|
||||
@@ -76,9 +76,10 @@ describe('KubernetesValidatorFunctions', () => {
|
||||
['a-b', true],
|
||||
['-a-b', false],
|
||||
['a-b-', false],
|
||||
['a--b', false],
|
||||
['a--b', true],
|
||||
['a_b', true],
|
||||
['a.b', true],
|
||||
['a..b', true],
|
||||
])(`isValidObjectName %p ? %p`, (value, matches) => {
|
||||
expect(KubernetesValidatorFunctions.isValidObjectName(value)).toBe(matches);
|
||||
});
|
||||
@@ -114,9 +115,10 @@ describe('KubernetesValidatorFunctions', () => {
|
||||
['a-b', true],
|
||||
['-a-b', false],
|
||||
['a-b-', false],
|
||||
['a--b', false],
|
||||
['a--b', true],
|
||||
['a_b', true],
|
||||
['a.b', true],
|
||||
['a..b', true],
|
||||
['a/a', true],
|
||||
['a-b.c/a', true],
|
||||
['a--b.c/a', false],
|
||||
@@ -150,9 +152,10 @@ describe('KubernetesValidatorFunctions', () => {
|
||||
['a-b', true],
|
||||
['-a-b', false],
|
||||
['a-b-', false],
|
||||
['a--b', false],
|
||||
['a--b', true],
|
||||
['a_b', true],
|
||||
['a.b', true],
|
||||
['a..b', true],
|
||||
])(`isValidLabelValue %p ? %p`, (value, matches) => {
|
||||
expect(KubernetesValidatorFunctions.isValidLabelValue(value)).toBe(matches);
|
||||
});
|
||||
@@ -169,9 +172,10 @@ describe('KubernetesValidatorFunctions', () => {
|
||||
['a-b', true],
|
||||
['-a-b', false],
|
||||
['a-b-', false],
|
||||
['a--b', false],
|
||||
['a--b', true],
|
||||
['a_b', true],
|
||||
['a.b', true],
|
||||
['a..b', true],
|
||||
['a/a', true],
|
||||
['a-b.c/a', true],
|
||||
['a--b.c/a', false],
|
||||
|
||||
@@ -48,7 +48,7 @@ export class KubernetesValidatorFunctions {
|
||||
typeof value === 'string' &&
|
||||
value.length >= 1 &&
|
||||
value.length <= 63 &&
|
||||
/^[a-z0-9A-Z]+([-_.][a-z0-9A-Z]+)*$/.test(value)
|
||||
/^([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9]$/.test(value)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user