Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More resilient logic for stripping the origin from page URLs #2164

Merged
merged 1 commit into from
Jan 8, 2025

Conversation

derrickreimer
Copy link
Contributor

The previous method for stripping the origin from absolute page URLs produces malformed output when the host string happens to appear multiple times in the URL.

// Old logic
"https://example.com/foo?return_to=https%3A%2F%example.com%2Fbar".split("example.com").pop() === "%2Fbar" 

// New logic
const url = new URL("https://example.com/foo?return_to=https%3A%2F%example.com%2Fbar")
url.pathname + url.search + url.hash === "/foo?return_to=https%3A%2F%example.com%2Fbar"

I had some trouble getting an automated test case to work in response.test.ts (they all seem to failing for me when I try to run vitest 🤔 ), but happy to take another crack at it with some guidance.

@joetannenbaum
Copy link
Contributor

Looks good, thank you!

@joetannenbaum joetannenbaum merged commit 3ac2fc8 into master Jan 8, 2025
8 checks passed
@joetannenbaum joetannenbaum deleted the fix-page-url-edge-case branch January 8, 2025 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants