Skip to content

fix(i18n): ensure the redirect pathname is non-empty#13730

Merged
florian-lefebvre merged 6 commits intowithastro:mainfrom
razonyang:patch-13729
Oct 8, 2025
Merged

fix(i18n): ensure the redirect pathname is non-empty#13730
florian-lefebvre merged 6 commits intowithastro:mainfrom
razonyang:patch-13729

Conversation

@razonyang
Copy link
Copy Markdown
Contributor

Closes #13729

Changes

  • What does this change?
  • Be short and concise. Bullet points can help!
  • Before/after screenshots can help as well.
  • Don't forget a changeset! pnpm exec changeset

Testing

Docs

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 30, 2025

🦋 Changeset detected

Latest commit: f32d957

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Apr 30, 2025
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 30, 2025

CodSpeed Performance Report

Merging #13730 will not alter performance

Comparing razonyang:patch-13729 (f32d957) with main (d1b3409)

Summary

✅ 6 untouched

Copy link
Copy Markdown
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

This PR isn't complete. We need:

For the test please create a new fixture inside the test/fixtures folder that represents the use case you're trying to fix. The update this file and add a test test case at the end. Ideally we want to test dev and build

@razonyang
Copy link
Copy Markdown
Contributor Author

Tests and changeset added, I hope I'm doing it correctly.

Comment on lines +389 to +390
// Ensure the pathname are non-empty. Redirects like "/fr" => "" may create infinite loops,
// as the "Location" response header is empty.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The comment is still unclear. For example, you don't explain why a redirect from /fr to / could create an infinite loop.

By the way, I believe this isn't the right fix, or to be more precise, the bug is at line 387 where we use the includes. Maybe we should check if base == "/", and if so, at line 388 we shouldn't remove the slash from the replace. What do you think?

Copy link
Copy Markdown
Contributor Author

@razonyang razonyang May 7, 2025

Choose a reason for hiding this comment

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

The root cause is that the Location response header is empty in the case that the /{any-lang} will be replaced as empty pathname.
And the empty Location should be considered as invalid URL, it will cause infinite loops (redirecting to current page again and again) on some browsers (e.g. Zen based on FireFox) or stop redirecting (just blank page) on some browsers like Chrome.

Maybe we should check if base == "/", and if so, at line 388 we shouldn't remove the slash from the replace.

I'm not sure if this approach will solve it, for exmaple, /fr/about will be replaced as //about if we do not replace the slash, then browser will redirect to http(s)://about, so in this approach, we will need to replace // to / as well. So in my opinion the if equal and then assign should have better performance than string replacing.

I'm not good at writing English, you can edit that file and adopt the tests 🤝 .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ping, any news?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense, thank you

@ematipico ematipico self-assigned this Oct 2, 2025
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
@florian-lefebvre florian-lefebvre merged commit 7260367 into withastro:main Oct 8, 2025
5 of 6 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinite redirects on i18n fallback when setting fallback to default locale that without prefix.

3 participants