Skip to content

Commit 99f5877

Browse files
ijreillyWeiko
authored andcommitted
[Fix] Do not allow names with whitespaces (#5542)
As per title
1 parent 83afb7b commit 99f5877

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/twenty-server/src/engine/metadata-modules/utils/__tests__/validate-metadata-name.spec.ts

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ describe('validateMetadataName', () => {
77

88
expect(validateMetadataName(input)).not.toThrow;
99
});
10+
it('throws error if string has spaces', () => {
11+
const input = 'name with spaces';
12+
13+
expect(() => validateMetadataName(input)).toThrow(InvalidStringException);
14+
});
15+
it('throws error if string starts with capital letter', () => {
16+
const input = 'StringStartingWithCapitalLetter';
17+
18+
expect(() => validateMetadataName(input)).toThrow(InvalidStringException);
19+
});
1020

1121
it('throws error if string has non latin characters', () => {
1222
const input = 'בְרִבְרִ';

packages/twenty-server/src/engine/metadata-modules/utils/validate-metadata-name.utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { InvalidStringException } from 'src/engine/metadata-modules/errors/InvalidStringException';
22

3-
const VALID_STRING_PATTERN = /^[a-zA-Z][a-zA-Z0-9 ]*$/;
3+
const VALID_STRING_PATTERN = /^[a-z][a-zA-Z0-9]*$/;
44

55
export const validateMetadataName = (string: string) => {
66
if (!string.match(VALID_STRING_PATTERN)) {

0 commit comments

Comments
 (0)