Skip to content

Commit

Permalink
Update validate-redirect-url.js
Browse files Browse the repository at this point in the history
Solving the failed tests
  • Loading branch information
BermetK123 committed Jan 15, 2025
1 parent 8d85d7b commit afbdf41
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions blocks/identity-block/utils/validate-redirect-url.js
Original file line number Diff line number Diff line change
@@ -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)

Check warning on line 6 in blocks/identity-block/utils/validate-redirect-url.js

View workflow job for this annotation

GitHub Actions / ensure_minimum_test_coverage_linting

Unexpected console statement

Check failure on line 6 in blocks/identity-block/utils/validate-redirect-url.js

View workflow job for this annotation

GitHub Actions / ensure_minimum_test_coverage_linting

Unexpected string concatenation
console.log("window " +window.location.origin)

Check warning on line 7 in blocks/identity-block/utils/validate-redirect-url.js

View workflow job for this annotation

GitHub Actions / ensure_minimum_test_coverage_linting

Unexpected console statement

Check failure on line 7 in blocks/identity-block/utils/validate-redirect-url.js

View workflow job for this annotation

GitHub Actions / ensure_minimum_test_coverage_linting

Unexpected string concatenation

if (urlObject.origin === window.location.origin) {
return urlObject.pathname;
if (urlObject.origin === window.location.origin) {
console.log("urlObject pth " + urlObject.pathname);

Check warning on line 10 in blocks/identity-block/utils/validate-redirect-url.js

View workflow job for this annotation

GitHub Actions / ensure_minimum_test_coverage_linting

Unexpected console statement

Check failure on line 10 in blocks/identity-block/utils/validate-redirect-url.js

View workflow job for this annotation

GitHub Actions / ensure_minimum_test_coverage_linting

Unexpected string concatenation

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;

0 comments on commit afbdf41

Please sign in to comment.