From f760f07072ab8a597fc4dcb6b1fb22cfa3b3df45 Mon Sep 17 00:00:00 2001 From: Anantesh G Date: Thu, 8 Aug 2024 00:15:35 +0530 Subject: [PATCH] Fixed restrictive URL sanity check #6570 Changes - Replaced the old regex with a new, more inclusive regex pattern. - Updated the isURL function to use the new pattern. --- packages/twenty-front/src/utils/is-url.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/twenty-front/src/utils/is-url.ts b/packages/twenty-front/src/utils/is-url.ts index bb6e8f7ee613..1e282a664f9e 100644 --- a/packages/twenty-front/src/utils/is-url.ts +++ b/packages/twenty-front/src/utils/is-url.ts @@ -1,7 +1,11 @@ import { isDefined } from './isDefined'; -export const isURL = (url: string | undefined | null) => - isDefined(url) && - url.match( - /^(https?:\/\/)?(www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/i, - ); +export const isURL = (url: string | undefined | null): boolean => { + if (!isDefined(url)) { + return false; + } + + const urlRegex = /^(https?:\/\/)?([\w-]+\.)+[\w-]+(\:\d+)?(\/[\w\-\.~%!$&'()*+,;=:@/]*)?(\?[;&a-z\-\_=\+%]+)?(#\S*)?$/i; + + return urlRegex.test(url); +};