Merge pull request #7283 from backstage/grantila/allow-more-characters-in-tags
Loosen catalog constraints on entity tag string validity.
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/catalog-model': patch
|
||||
---
|
||||
|
||||
Loosen constraints on what's a valid catalog entity tag name (include + and #)
|
||||
@@ -50,6 +50,7 @@ export class CommonValidatorFunctions {
|
||||
isValidSuffix: (value: string) => boolean,
|
||||
): boolean;
|
||||
static isValidString(value: unknown): boolean;
|
||||
static isValidTag(value: unknown): boolean;
|
||||
static isValidUrl(value: unknown): boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,10 @@ export class FieldFormatEntityPolicy implements EntityPolicy {
|
||||
expectation =
|
||||
'a string that is sequences of [a-z0-9] separated by [-], at most 63 characters in total';
|
||||
break;
|
||||
case 'isValidTag':
|
||||
expectation =
|
||||
'a string that is sequences of [a-z0-9+#] separated by [-], at most 63 characters in total';
|
||||
break;
|
||||
case 'isValidAnnotationValue':
|
||||
expectation = 'a string';
|
||||
break;
|
||||
|
||||
@@ -162,6 +162,31 @@ describe('CommonValidatorFunctions', () => {
|
||||
expect(CommonValidatorFunctions.isValidDnsLabel(value)).toBe(result);
|
||||
});
|
||||
|
||||
it.each([
|
||||
// These are identical to isValidDnsLabel
|
||||
[null, false],
|
||||
[7, false],
|
||||
['', false],
|
||||
['a', true],
|
||||
['a-b', true],
|
||||
['-a-b', false],
|
||||
['a-b-', false],
|
||||
['a--b', false],
|
||||
['a_b', false],
|
||||
[`${'a'.repeat(63)}`, true],
|
||||
[`${'a'.repeat(64)}`, false],
|
||||
// Tags can have other characters though
|
||||
['a+b', true],
|
||||
['+a+b', true],
|
||||
['a+b+', true],
|
||||
['a++b', true],
|
||||
['c++', true],
|
||||
['c#', true],
|
||||
['#c++', true],
|
||||
])(`isValidTag %p ? %p`, (value, result) => {
|
||||
expect(CommonValidatorFunctions.isValidTag(value)).toBe(result);
|
||||
});
|
||||
|
||||
it.each([
|
||||
[null, false],
|
||||
[7, false],
|
||||
|
||||
@@ -95,6 +95,20 @@ export class CommonValidatorFunctions {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the value is a valid tag.
|
||||
*
|
||||
* @param value - The value to check
|
||||
*/
|
||||
static isValidTag(value: unknown): boolean {
|
||||
return (
|
||||
typeof value === 'string' &&
|
||||
value.length >= 1 &&
|
||||
value.length <= 63 &&
|
||||
/^[a-z0-9+#]+(\-[a-z0-9+#]+)*$/.test(value)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the value is a valid URL.
|
||||
*
|
||||
|
||||
@@ -27,7 +27,7 @@ const defaultValidators: Validators = {
|
||||
isValidLabelValue: KubernetesValidatorFunctions.isValidLabelValue,
|
||||
isValidAnnotationKey: KubernetesValidatorFunctions.isValidAnnotationKey,
|
||||
isValidAnnotationValue: KubernetesValidatorFunctions.isValidAnnotationValue,
|
||||
isValidTag: CommonValidatorFunctions.isValidDnsLabel,
|
||||
isValidTag: CommonValidatorFunctions.isValidTag,
|
||||
};
|
||||
|
||||
/** @public */
|
||||
|
||||
Reference in New Issue
Block a user