Skip to content

Commit

Permalink
fix: CQDG-817 review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
adipaul1981 committed Aug 2, 2024
1 parent a741716 commit 8b01ede
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const UUID_VERSION = 4;
export const NAME_REGEX = /^[\u0027-\u0029\u002F-\u0039\u0040\u0061-\u007A\u00C0-\uFFFF ,.'\-_]+$/iu; // see regex.test.ts to understand the regex
export const SET_FILTER_NAME_REGEX = /^[\w\s()\-_,.|:'[\]]{1,200}$/iu; // see regex.test.ts to understand the regex
export const SET_FILTER_NAME_REGEX = /^[\w\s()\-_,.|:'[\]]{1,199}$/iu; // see regex.test.ts to understand the regex
export const LINKEDIN_REGEX = /^(http(s)?:\/\/)?([\w]+\.)?linkedin\.com\/(pub|in|profile)\/([-a-zA-Z0-9]+)\/*/iu;
export const MAX_LENGTH_PER_ROLE = 100;
29 changes: 18 additions & 11 deletions src/utils/regex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,23 @@ describe('NAME_REGEX', () => {
});

describe('SET_NAME_REGEX', () => {
it('should allow alphanumeric lower and uppercase', () => {
it('should allow these characters', () => {
expect(SET_FILTER_NAME_REGEX.test('ThisIsAlphanumeric123')).toBeTruthy();
expect(SET_FILTER_NAME_REGEX.test(`set_1 (HP:123.1) | [Mondo:1,23-1]`)).toBeTruthy();
expect(SET_FILTER_NAME_REGEX.test('a(a')).toBeTruthy();
expect(SET_FILTER_NAME_REGEX.test('a)a')).toBeTruthy();
expect(SET_FILTER_NAME_REGEX.test("a'a")).toBeTruthy();
expect(SET_FILTER_NAME_REGEX.test('a-a')).toBeTruthy();
expect(SET_FILTER_NAME_REGEX.test('a_a')).toBeTruthy();
expect(SET_FILTER_NAME_REGEX.test('a,a')).toBeTruthy();
expect(SET_FILTER_NAME_REGEX.test('a.a')).toBeTruthy();
expect(SET_FILTER_NAME_REGEX.test('a[a')).toBeTruthy();
expect(SET_FILTER_NAME_REGEX.test('a]a')).toBeTruthy();
expect(SET_FILTER_NAME_REGEX.test('a:a')).toBeTruthy();
expect(SET_FILTER_NAME_REGEX.test('a|a')).toBeTruthy();
});
it(`should allow / @ ( ) ' - _ , . space`, () => {
expect(SET_FILTER_NAME_REGEX.test(`( ) ' - _ , . [ ] : |`)).toBeTruthy();
});
it(`should not allow ; { } ^ ! " # $ % & * + < = > ? \\ ~`, () => {

it(`should not allow / @ ; { } ^ ! " # $ % & * + < = > ? \\ ~`, () => {
expect(SET_FILTER_NAME_REGEX.test('a;a')).toBeFalsy();
expect(SET_FILTER_NAME_REGEX.test('a{a')).toBeFalsy();
expect(SET_FILTER_NAME_REGEX.test('a}a')).toBeFalsy();
Expand All @@ -74,13 +84,10 @@ describe('SET_NAME_REGEX', () => {
expect(SET_FILTER_NAME_REGEX.test('a?a')).toBeFalsy();
expect(SET_FILTER_NAME_REGEX.test('a\\a')).toBeFalsy();
expect(SET_FILTER_NAME_REGEX.test('a~a')).toBeFalsy();
expect(SET_FILTER_NAME_REGEX.test('a@a')).toBeFalsy();
expect(SET_FILTER_NAME_REGEX.test('a/a')).toBeFalsy();
});
it(`should not allow more than 200 character names`, () => {
expect(
SET_FILTER_NAME_REGEX.test(
'aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa ' +
'aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa aaaaaaaaaa',
),
).toBeFalsy();
expect(SET_FILTER_NAME_REGEX.test('a'.repeat(200))).toBeFalsy();
});
});

0 comments on commit 8b01ede

Please sign in to comment.