From 8b01ede43533dbcc0608cf15448e83441e7009fd Mon Sep 17 00:00:00 2001 From: Adrian Date: Fri, 2 Aug 2024 15:15:07 -0400 Subject: [PATCH] fix: CQDG-817 review comments --- src/utils/constants.ts | 2 +- src/utils/regex.test.ts | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 1b11645..c21ad09 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -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; diff --git a/src/utils/regex.test.ts b/src/utils/regex.test.ts index b6a8360..4cf6d64 100644 --- a/src/utils/regex.test.ts +++ b/src/utils/regex.test.ts @@ -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(); @@ -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(); }); });