Skip to content

Backslash in path parameters are incorrectly restored from URL #3962

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

Open
DreierF opened this issue Apr 8, 2025 · 0 comments · May be fixed by #3987
Open

Backslash in path parameters are incorrectly restored from URL #3962

DreierF opened this issue Apr 8, 2025 · 0 comments · May be fixed by #3987
Labels
bug Something isn't working

Comments

@DreierF
Copy link

DreierF commented Apr 8, 2025

Which project does this relate to?

Router

Describe the bug

When navigating to a route with a path parameter (or splash) where the value contains a backslash, everything works at first. But when reloading the page or navigating back to the page the path restored from the URL differs from the original URL.

Your Example Website or App

https://stackblitz.com/edit/tanstack-router-yoii3nte?file=src%2Froutes%2Fb.%24postId.tsx

Steps to Reproduce the Bug or Issue

  1. Open the preview in a new tab (so that you can see the full URL)
  2. Click one of the "Splat route" or "Path param route" links
  3. Reload the page
  4. Observe that the URL changes and the page content changes as well.

Expected behavior

As a user I expect that reloading a page shows the same route and same parameters than before.

Screenshots or Videos

Screen.Recording.2025-04-08.at.15.45.59.mov

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 135

Additional context

The problem seems to be that after the reload, i.e., during the initial sync with the URL replaceState is called with the decoded "/b/test[s\%2F.\%2Fparameter]" as URL. replaceState turns \ into /.
This happens because interpolatePath at https://github.com/TanStack/router/blob/main/packages/router-core/src/router.ts#L1610 is called with "/b/test[s\%2F.\%2Fparameter]" as pathname instead of "/b/$postId", which is the case during a regular navigation. This would then take care of the escaping. Hence I assume the issue is within resolvePathWithBase (https://github.com/TanStack/router/blob/main/packages/router-core/src/router.ts#L1567) which returns the pathname, but I feel like I don't have enough context knowledge to judge at which point exactly the current behavior deviates from the expected behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants