diff --git a/src/components/pages/AppOverview/index.tsx b/src/components/pages/AppOverview/index.tsx index 20441c8c8..e4c39c297 100644 --- a/src/components/pages/AppOverview/index.tsx +++ b/src/components/pages/AppOverview/index.tsx @@ -57,6 +57,7 @@ import { fetchImageWithToken } from 'services/ImageService' import { setCurrentActiveStep } from 'features/appManagement/slice' import { setAppId, setAppStatus } from 'features/appManagement/actions' import NoItems from '../NoItems' +import { isValidAppOverviewSearch } from 'types/Patterns' export default function AppOverview() { const { t } = useTranslation() @@ -222,8 +223,7 @@ export default function AppOverview() { const doSearch = useCallback( (expr: string) => { - const validateExpr = /^[ A-Za-z]*$/.test(expr) - if (!validateExpr) { + if (!isValidAppOverviewSearch(expr)) { return } setSearchExpr(expr) diff --git a/src/types/Patterns.test.ts b/src/types/Patterns.test.ts index 803569c30..fa79c6fe2 100644 --- a/src/types/Patterns.test.ts +++ b/src/types/Patterns.test.ts @@ -30,6 +30,7 @@ import { isClientID, isPersonName, isSearchUserEmail, + isValidAppOverviewSearch, } from './Patterns' const TESTDATA = { @@ -255,6 +256,10 @@ const TESTDATA = { ], invalid: ['()*&^%$#/\\?><,`~'], }, + appOverview: { + valid: ['sa-12', '1234', 'Test123!@#'], + invalid: ['🚀 Rocket!', 'Invalid\nNewLine'], + }, } describe('Input Pattern Tests', () => { @@ -354,4 +359,12 @@ describe('Input Pattern Tests', () => { expect(isSearchUserEmail(expr)).toBe(false) }) }) + it('validate appoverview search', () => { + TESTDATA.appOverview.valid.forEach((expr) => { + expect(isValidAppOverviewSearch(expr)).toBe(true) + }) + TESTDATA.appOverview.invalid.forEach((expr) => { + expect(isValidAppOverviewSearch(expr)).toBe(false) + }) + }) }) diff --git a/src/types/Patterns.ts b/src/types/Patterns.ts index c9253a092..0b3994971 100644 --- a/src/types/Patterns.ts +++ b/src/types/Patterns.ts @@ -118,6 +118,9 @@ export const Patterns = { /^(?!.*\s$)(?=[a-zA-Z\d-]{0,10}[-\s]?[a-zA-Z\d-]{0,10}$)[a-zA-Z\d\s-]{2,10}$/, }, EMAIL_SEARCH: /^[ A-Za-z0-9._!@+-]*$/, + appOverview: { + SEARCH: /^[ A-Za-z0-9!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]*$/, + }, } export const isEmpty = (expr: string) => !expr || expr.trim() === '' @@ -208,5 +211,7 @@ export const isPostalCode = (expr: string) => Patterns.companyData.POSTAL_CODE.test(expr) export const isSearchUserEmail = (expr: string) => Patterns.EMAIL_SEARCH.test(expr) +export const isValidAppOverviewSearch = (expr: string) => + Patterns.appOverview.SEARCH.test(expr) export default Patterns