From 9fe6e552a4de7f0c796558ace30bec97431f05b6 Mon Sep 17 00:00:00 2001 From: BermetK123 Date: Tue, 14 Jan 2025 13:35:51 -0600 Subject: [PATCH 1/4] 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; From 8d85d7b6a6e45c47f084f01c6bcca773cde82636 Mon Sep 17 00:00:00 2001 From: BermetK123 Date: Tue, 14 Jan 2025 13:37:01 -0600 Subject: [PATCH 2/4] Update validate-redirect-url.js --- blocks/identity-block/utils/validate-redirect-url.js | 1 - 1 file changed, 1 deletion(-) diff --git a/blocks/identity-block/utils/validate-redirect-url.js b/blocks/identity-block/utils/validate-redirect-url.js index 31c04e107..c23c7b6d6 100644 --- a/blocks/identity-block/utils/validate-redirect-url.js +++ b/blocks/identity-block/utils/validate-redirect-url.js @@ -5,7 +5,6 @@ const validateURL = (url) => { const urlObject = new URL(url, window.location.origin); if (urlObject.origin === window.location.origin) { - console.log(urlObject.pathname+"bermet") return urlObject.pathname; } } catch (e) { From afbdf41dcafc795f036593fb9ea59d3a357806a6 Mon Sep 17 00:00:00 2001 From: BermetK123 Date: Wed, 15 Jan 2025 09:07:47 -0600 Subject: [PATCH 3/4] Update validate-redirect-url.js Solving the failed tests --- .../utils/validate-redirect-url.js | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/blocks/identity-block/utils/validate-redirect-url.js b/blocks/identity-block/utils/validate-redirect-url.js index c23c7b6d6..2acbd5696 100644 --- a/blocks/identity-block/utils/validate-redirect-url.js +++ b/blocks/identity-block/utils/validate-redirect-url.js @@ -1,20 +1,35 @@ const validateURL = (url) => { - if (!url) return null; + if (!url) return null; - try { - const urlObject = new URL(url, window.location.origin); + try { + const urlObject = new URL(url, window.location.origin); + console.log("urlObject " + urlObject.origin) + console.log("window " +window.location.origin) - if (urlObject.origin === window.location.origin) { - return urlObject.pathname; + if (urlObject.origin === window.location.origin) { + console.log("urlObject pth " + urlObject.pathname); + + if(urlObject.pathname === "/"){ + return urlObject.pathname + } + + if(urlObject.pathname !== "/"){ + return `${urlObject.origin}${urlObject.pathname}` + } + } + + sessionStorage.setItem("ArcXP_redirectUrl", "/"); + return "/"; + } catch (error) { + const storedRedirect = sessionStorage.getItem("ArcXP_redirectUrl"); + if (storedRedirect && storedRedirect.startsWith("/")) { + return storedRedirect; } - } catch (e) { + // Default to "/" sessionStorage.setItem("ArcXP_redirectUrl", "/"); return "/"; - } - - sessionStorage.setItem("ArcXP_redirectUrl", "/"); - return "/"; + } }; -export default validateURL; +export default validateURL; \ No newline at end of file From a4fc535421b605b6b835fb23bed7dd102a528775 Mon Sep 17 00:00:00 2001 From: BermetK123 Date: Wed, 15 Jan 2025 09:08:55 -0600 Subject: [PATCH 4/4] removing console logs --- blocks/identity-block/utils/validate-redirect-url.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/blocks/identity-block/utils/validate-redirect-url.js b/blocks/identity-block/utils/validate-redirect-url.js index 2acbd5696..49212341f 100644 --- a/blocks/identity-block/utils/validate-redirect-url.js +++ b/blocks/identity-block/utils/validate-redirect-url.js @@ -3,11 +3,8 @@ const validateURL = (url) => { try { const urlObject = new URL(url, window.location.origin); - console.log("urlObject " + urlObject.origin) - console.log("window " +window.location.origin) if (urlObject.origin === window.location.origin) { - console.log("urlObject pth " + urlObject.pathname); if(urlObject.pathname === "/"){ return urlObject.pathname @@ -17,9 +14,9 @@ const validateURL = (url) => { return `${urlObject.origin}${urlObject.pathname}` } } - sessionStorage.setItem("ArcXP_redirectUrl", "/"); return "/"; + } catch (error) { const storedRedirect = sessionStorage.getItem("ArcXP_redirectUrl"); if (storedRedirect && storedRedirect.startsWith("/")) {