From 11ae5222a18f625f402956ba4962511f18ea9e61 Mon Sep 17 00:00:00 2001 From: SanjalKatiyar Date: Wed, 3 Apr 2024 11:19:47 +0530 Subject: [PATCH] fix 'catastrophic backtracking' issue with text-input regex --- packages/shared/src/utils/validation.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/shared/src/utils/validation.ts b/packages/shared/src/utils/validation.ts index a8220a316..a63f15cb1 100644 --- a/packages/shared/src/utils/validation.ts +++ b/packages/shared/src/utils/validation.ts @@ -1,14 +1,13 @@ /** * Starts and ends with a lowercase letter or number */ -export const startAndEndsWithAlphanumerics = - /^(?![\W])([a-z0-9]|[\W]*([a-z0-9]))+(?![\W])$/; +export const startAndEndsWithAlphanumerics = /^[a-z0-9](.*[a-z0-9])?$/; /** * Only lowercase letters, numbers, non-consecutive periods, or hyphens */ export const alphaNumericsPeriodsHyphensNonConsecutive = - /^[a-z0-9]+([a-z0-9]|([-.](?![-.])))*[a-z0-9]*$/; + /(^[a-z0-9]|^([-.](?![-.])))+([a-z0-9]|([-.](?![-.])))*[a-z0-9]*$/; export default { startAndEndsWithAlphanumerics,