From 3c5196cf06c43835c9dda151ff1f5d17bd48600a Mon Sep 17 00:00:00 2001 From: Jorge Padilla Date: Wed, 6 Sep 2023 13:30:43 -0500 Subject: [PATCH] fix(frontend): fix method to parse url (#3127) --- web/src/utils/Common.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/web/src/utils/Common.ts b/web/src/utils/Common.ts index 4c0005dcfd..6cdc3dab52 100644 --- a/web/src/utils/Common.ts +++ b/web/src/utils/Common.ts @@ -80,19 +80,10 @@ export const getIsValidUrl = (url: string): boolean => { } }; -const regex = - '(?:\\S+(?::\\S*)?@)?(?:(?:(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[0-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)(?:\\.(?:[a-z\\u00a1-\\uffff0-9]+-?)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\.(?:[a-z\\u00a1-\\uffff]{2,})))|localhost)(?::\\d{2,5})?(?:(/|\\?|#)[^\\s]*)?$'; - export const getParsedURL = (rawUrl: string): URL => { - const urlRegex = new RegExp(regex, 'i'); - - const [matchedUrl = ''] = rawUrl.match(urlRegex) || []; - - if (!matchedUrl) throw new Error('Invalid URL'); - - if (!!matchedUrl && !matchedUrl.startsWith('http')) { - return new URL(`http://${matchedUrl}`); + if (!!rawUrl && !rawUrl.startsWith('http')) { + return new URL(`http://${rawUrl}`); } - return new URL(matchedUrl); + return new URL(rawUrl); };