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

Fix infinite redirect when a double slash appears in a URL #2449

Merged
merged 2 commits into from
Aug 20, 2024

Conversation

blittle
Copy link
Contributor

@blittle blittle commented Aug 19, 2024

This PR does two things:

  1. Take @brophdawg11's suggestion to resolve this in Oxygen: double slash followed by any char after domain causes infinite page reloading remix-run/remix#9692 (comment) by detecting the double slash, and redirecting with a single slash. I assume this is okay? Are there situations where the URL might have encoded data with a double slash that would break?

  2. Fix a bug where in local development the request object would not contain the localhost domain because new URL('//test', 'http://localhost/').href produce http://test/'

🎩

  1. Load the skeleton template with the URL: http://localhost:3000//test. Should redirect with the double slash removed.
  2. Load the skeleton template with the URL: http://localhost:3000/products//snowboard. Should redirect with the double slash removed.

Copy link
Contributor

shopify bot commented Aug 19, 2024

Oxygen deployed a preview of your bl-fix-slash-redirect branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment August 19, 2024 5:48 PM
metaobjects ✅ Successful (Logs) Preview deployment Inspect deployment August 19, 2024 5:48 PM
custom-cart-method ✅ Successful (Logs) Preview deployment Inspect deployment August 19, 2024 5:48 PM
third-party-queries-caching ✅ Successful (Logs) Preview deployment Inspect deployment August 19, 2024 5:48 PM
classic-remix ✅ Successful (Logs) Preview deployment Inspect deployment August 19, 2024 5:48 PM
sitemap ✅ Successful (Logs) Preview deployment Inspect deployment August 19, 2024 5:48 PM

Learn more about Hydrogen's GitHub integration.

@@ -10,13 +10,12 @@ import type {ViteDevServer} from 'vite';
*/
export function toURL(req: string | IncomingMessage = '/', origin?: string) {
const isRequest = typeof req !== 'string';
const pathname = (isRequest ? req.url : req) || '/';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using the second argument to new URL, just manually concatenate the origin with the pathname.

@blittle blittle merged commit 664a09d into main Aug 20, 2024
13 checks passed
@blittle blittle deleted the bl-fix-slash-redirect branch August 20, 2024 15:06
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