From 9fe6e552a4de7f0c796558ace30bec97431f05b6 Mon Sep 17 00:00:00 2001 From: BermetK123 Date: Tue, 14 Jan 2025 13:35:51 -0600 Subject: [PATCH] Update validate-redirect-url.js --- .../utils/validate-redirect-url.js | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/blocks/identity-block/utils/validate-redirect-url.js b/blocks/identity-block/utils/validate-redirect-url.js index 84f8a5fea..31c04e107 100644 --- a/blocks/identity-block/utils/validate-redirect-url.js +++ b/blocks/identity-block/utils/validate-redirect-url.js @@ -1,24 +1,21 @@ const validateURL = (url) => { - if (!url) return null; - const validationRegEx = /^\/[^/].*$/; - const valid = validationRegEx.test(url); + if (!url) return null; - if (valid) { - return `${window.location.origin}${url}`; - } + try { + const urlObject = new URL(url, window.location.origin); - if (url === "/") { - return url; - } + if (urlObject.origin === window.location.origin) { + console.log(urlObject.pathname+"bermet") + return urlObject.pathname; + } + } catch (e) { - const urlLocation = new URL(url); + sessionStorage.setItem("ArcXP_redirectUrl", "/"); + return "/"; + } - if (urlLocation.origin === window.location.origin) { - return url; - } - - sessionStorage.setItem("ArcXP_redirectUrl", "/"); - return "/"; + sessionStorage.setItem("ArcXP_redirectUrl", "/"); + return "/"; }; export default validateURL;