Skip to content

Commit

Permalink
[Fix] Do not allow names with whitespaces (twentyhq#5542)
Browse files Browse the repository at this point in the history
As per title
  • Loading branch information
ijreilly committed May 23, 2024
1 parent 04bf697 commit 6b1d4e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 'בְרִבְרִ';
Expand Down
Original file line number Diff line number Diff line change
@@ -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)) {
Expand Down

0 comments on commit 6b1d4e0

Please sign in to comment.