Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Do not allow names with whitespaces #5542

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ describe('validateMetadataName', () => {

expect(validateMetadataName(input)).not.toThrow;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use toThrow() instead of not.toThrow to correctly assert that no exception is thrown.

});
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
Loading