-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: Backslash incorrectly decoded (#3962) #5534
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughRemoves per-segment in-path URI decoding for percent-encoded sequences in regular pathname segments; segments are now left as-is. Adds a test ensuring encoded backslashes in path parameters are preserved. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller
participant parsePathname
participant PathLogic
Caller->>parsePathname: parse raw pathname (e.g. "/foo%5Cbar")
parsePathname->>PathLogic: identify partToMatch (regular segment)
alt Previous behavior
PathLogic->>PathLogic: split on "%25" and decode segments (decodeURI)
PathLogic->>parsePathname: rejoin decoded segments
else New behavior
PathLogic-->>parsePathname: return partToMatch unchanged
end
parsePathname-->>Caller: return parsed segments (preserve %5C)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/router-core/tests/path.test.ts (1)
348-353
: Consider adding a complementary matching test.The test correctly verifies that backslashes and percent signs in parameters are properly encoded during path interpolation. However, given that the PR fixes incorrect decoding behavior (per the title), consider adding a matching test that verifies the reverse operation works correctly.
Add this test in the
matchPathname
→path param(s) matching
section to verify bidirectional correctness:{ name: 'should correctly decode backslashes and percent-encoded sequences in path parameters', input: '/b/test%5Bs%5C%252F.%5C%252Fparameter%5D', matchingOptions: { to: '/b/$postId', }, expectedMatchedParams: { postId: 'test[s\\%2F.\\%2Fparameter]' }, },This ensures that:
- The encoded path can be matched against the route pattern
- The parameter is correctly decoded back to the original value
- The fix for incorrect decoding is validated in both directions
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/router-core/src/path.ts
(1 hunks)packages/router-core/tests/path.test.ts
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
packages/router-core/tests/path.test.ts
packages/router-core/src/path.ts
packages/router-core/**
📄 CodeRabbit inference engine (AGENTS.md)
Keep framework-agnostic core router logic in packages/router-core/
Files:
packages/router-core/tests/path.test.ts
packages/router-core/src/path.ts
🔇 Additional comments (1)
packages/router-core/src/path.ts (1)
348-352
: LGTM: Pathname segments now correctly preserved without parsing-layer decoding.Removing the URI decoding logic from
baseParsePathname
is the correct fix. The git history confirms this commit ("fix: Backslash incorrectly decoded #3962") addresses a double-decoding bug.Verification shows:
- No parsePathname tests pass encoded strings and expect decoding (no
%
in test inputs)- decodeURIComponent is already in place in matchByPath (lines 688, 692, 744, 783) for boundary decoding
- The three-layer architecture is intact: parse (preserve as-is) → match (decode at boundaries) → interpolate (encode at boundaries)
- This change aligns with the correct encoding/decoding pattern
Thanks for the this. When replicating the test on its own into main, without the accompanied fix, I'm expecting the test to fail. Unfortunately, this passes already without the above changes. We should have a failing test to which the applied changes resolve the issue. This is to ensure that we both understand the need for the change and to ensure future updates don't inadvertently break the functionality without the test giving a false positive. |
4490a45
to
e675ee2
Compare
🤦♂️ Good catch @nlynzaad! The new test fails without the change. |
Summary by CodeRabbit
Bug Fixes
Tests