From 520c60a8e798c23f3d393187083ded0c70821c7c Mon Sep 17 00:00:00 2001 From: medchedli Date: Wed, 4 Jun 2025 17:36:57 +0100 Subject: [PATCH] fix: consolidate type checks for string inputs in formatWithSlashes and extractRegexBody functions --- frontend/src/utils/string.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/frontend/src/utils/string.ts b/frontend/src/utils/string.ts index 4de778e9..669d8af6 100644 --- a/frontend/src/utils/string.ts +++ b/frontend/src/utils/string.ts @@ -30,8 +30,7 @@ export const isRegexString = (str: any) => { * Ensures value is wrapped in slashes: /value/ */ export const formatWithSlashes = (value: string): string => { - if (!value) return "/"; - if (typeof value !== "string") return "/"; + if (!value || typeof value !== "string") return "/"; if (!value.startsWith("/")) value = "/" + value; if (!value.endsWith("/")) value = value + "/"; @@ -42,8 +41,12 @@ export const formatWithSlashes = (value: string): string => { * Extracts the inner regex from /.../ */ export const extractRegexBody = (value: string | undefined): string => { - if (typeof value !== "string") return ""; - if (value && value.startsWith("/") && value.endsWith("/")) { + if ( + value && + typeof value === "string" && + value.startsWith("/") && + value.endsWith("/") + ) { return value.slice(1, -1); }