[Fix] Do not allow names with whitespaces (#5542)

As per title
This commit is contained in:
Marie
2024-05-23 07:43:09 +02:00
committed by GitHub
parent 04bf697b25
commit 6b1d4e0744
2 changed files with 11 additions and 1 deletions

View File

@ -7,6 +7,16 @@ describe('validateMetadataName', () => {
expect(validateMetadataName(input)).not.toThrow;
});
it('throws error if string has spaces', () => {
const input = 'name with spaces';
expect(() => validateMetadataName(input)).toThrow(InvalidStringException);
});
it('throws error if string starts with capital letter', () => {
const input = 'StringStartingWithCapitalLetter';
expect(() => validateMetadataName(input)).toThrow(InvalidStringException);
});
it('throws error if string has non latin characters', () => {
const input = 'בְרִבְרִ';

View File

@ -1,6 +1,6 @@
import { InvalidStringException } from 'src/engine/metadata-modules/errors/InvalidStringException';
const VALID_STRING_PATTERN = /^[a-zA-Z][a-zA-Z0-9 ]*$/;
const VALID_STRING_PATTERN = /^[a-z][a-zA-Z0-9]*$/;
export const validateMetadataName = (string: string) => {
if (!string.match(VALID_STRING_PATTERN)) {