[fix] Support non latin characters in schema names (#5063)
Fixes #4943 ## How was it tested? Local (front + /metadata) Unit tests for utils --------- Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
@ -0,0 +1,22 @@
|
||||
import { InvalidStringException } from 'src/engine/metadata-modules/errors/InvalidStringException';
|
||||
import { validateMetadataName } from 'src/engine/metadata-modules/utils/validate-metadata-name.utils';
|
||||
|
||||
describe('validateMetadataName', () => {
|
||||
it('does not throw if string is valid', () => {
|
||||
const input = 'testName';
|
||||
|
||||
expect(validateMetadataName(input)).not.toThrow;
|
||||
});
|
||||
|
||||
it('throws error if string has non latin characters', () => {
|
||||
const input = 'בְרִבְרִ';
|
||||
|
||||
expect(() => validateMetadataName(input)).toThrow(InvalidStringException);
|
||||
});
|
||||
|
||||
it('throws error if starts with digits', () => {
|
||||
const input = '123string';
|
||||
|
||||
expect(() => validateMetadataName(input)).toThrow(InvalidStringException);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,9 @@
|
||||
import { InvalidStringException } from 'src/engine/metadata-modules/errors/InvalidStringException';
|
||||
|
||||
const VALID_STRING_PATTERN = /^[a-zA-Z][a-zA-Z0-9 ]*$/;
|
||||
|
||||
export const validateMetadataName = (string: string) => {
|
||||
if (!string.match(VALID_STRING_PATTERN)) {
|
||||
throw new InvalidStringException(string);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user