fix(router-core): keep percent-encoded caret in paths to prevent an infinite redirect loop - #8046
Open
FrancoKaddour wants to merge 2 commits into
Open
Conversation
…rect loop The WHATWG URL path percent-encode set includes U+005E (^), but the PATH_UNSAFE_RE set introduced in TanStack#7695 did not. decodeURI decodes %5E to a literal caret which nothing re-encodes, while browsers and the WHATWG URL parser (new URL) always re-encode it -- so the canonical publicHref built from the decoded pathname never matches the incoming raw href and the server canonicalization redirect fires on every request: GET /%5E -> 307 /^ -> browser re-encodes -> GET /%5E, forever (ERR_TOO_MANY_REDIRECTS). Adding ^ to the preserved set makes the decode/encode round-trip stable, matching the behavior of the other path percent-encode set characters. Fixes TanStack#8041.
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe router-core path sanitizer now percent-encodes caret characters. Tests verify preservation of encoded carets and uppercase normalization of lowercase escapes. A patch changeset documents the fix. ChangesCaret path encoding
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
FrancoKaddour
marked this pull request as ready for review
August 11, 2026 22:42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #8041
The WHATWG URL path percent-encode set includes U+005E (
^), but thePATH_UNSAFE_REset introduced in #7695 didn't.decodeURIdecodes%5Eto a literal caret which nothing re-encodes, while browsers and the WHATWG URL parser always re-encode it — so the canonicalpublicHrefbuilt from the decoded pathname never matches the incoming raw href, and the server canonicalization redirect fires on every request:GET /%5E→307 /^→ browser re-encodes →GET /%5E, forever.Adding
^to the preserved set makes the decode/encode round-trip stable, exactly like the other characters #7695 covered. Lowercase%5enormalizes to%5Ein a single converging redirect, same as%7b→%7Btoday.Tests follow the existing "WHATWG path percent-encode set preserved" suite; both fail without the one-character fix.
Summary by CodeRabbit
%5E.