fix: Backslash incorrectly decoded (#3962) #5534
main fromrefs/pull/5534/head·opened Summary by CodeRabbit#
Bug Fixes
- Pathname parsing now preserves percent-encoded sequences (e.g., encoded backslashes) within path segments instead of decoding them, preventing unintended changes to parameters.
Tests
- Added coverage to verify encoded characters in path parameters remain intact during parsing.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-core
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) matchingsection 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
📥 Commits
Reviewing files that changed from the base of the PR and between 4693e0e3d4340238a79f26a2a9b102b4e670ea2a and 4490a45747021619c0dbc0f117855c9bc1f005cf.
📒 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.tspackages/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.tspackages/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
baseParsePathnameis 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.
🤦♂️ Good catch @nlynzaad! The new test fails without the change.
🤖 Nx Cloud AI Fix Eligible#
To disable these notifications, a workspace admin can disable them [in workspace settings.](https://cloud.nx.app/orgs/6412ca9d1c251d000efa21ba/workspaces/6442f7de8226a6291646a813/settings#selfHealingCISettings?utm_source=pull-request&utm_medium=comment)An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.
View your CI Pipeline Execution ↗ for commit e675ee2cdc350d25c32dfb57f18973c060a2aa85
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...❌ Failed 6m 36s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 1m 27s View ↗
☁️ Nx Cloud last updated this comment at
2025-10-25 04:26:58UTCMore templates
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-solid-start-example-bare
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-static
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
@tanstack/arktype-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5534@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5534@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5534@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5534@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5534@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5534@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5534@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5534@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5534@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5534@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5534@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5534@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5534@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5534@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5534@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5534@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5534@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5534@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5534@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5534@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5534@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5534@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5534@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5534@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5534@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5534@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5534@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5534@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5534@tanstack/start-static-server-functions
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5534@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5534@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5534@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5534@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5534commit:
e675ee2@DreierF thanks again for this. it helped a lot to understand the problem and the road to a solution. unfortunately, we need to decode the path segments and should just exclude the backslash similar to how percentage signs are currently handled.
I've been able to wire up a decoding function that is able to handle these requirements as well as any further additions we might need to specifically ignore.
I'm closing this PR in favour of #5663
nlynzaad(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Walkthrough#
Removes 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#
packages/router-core/src/path.ts%25-delimited) and decoded each pathname segment;partToMatchis now preserved without per-segmentdecodeURIdecoding.packages/router-core/tests/path.test.ts/foo%5Cbarpreserves the%5C(backslash) in the resulting path segment.Sequence Diagram(s)#
Estimated code review effort#
🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs#
packages/router-core/src/path.ts, closely related to this change.Poem#
Pre-merge checks and finishing touches#
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 4490a45747021619c0dbc0f117855c9bc1f005cf and e675ee2cdc350d25c32dfb57f18973c060a2aa85.
📒 Files selected for processing (2)
packages/router-core/src/path.ts(1 hunks)packages/router-core/tests/path.test.ts(1 hunks)🚧 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.
❤️ Share