You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
URLs cannot safely be stored in search parameters #4282
When a url-encoded string (for example, a continue URL on login pages) is provided as a search parameter, it is forcibly unescaped on parse.
For URLs that do not include escaped characters such as / (%2F), ? (%3F), or # (%23), this is totally fine. But this forced unescaping can change the structure of the URL:
If I navigate with:
navigate({
to: "someRoute",
search: {
continueUrl: "/foo%2Fbar"
}
})
Then someRoute's validateSearch callback will be called with: { continueUrl: "/foo/bar" }. Which is a meaningfully different
Similarly strings like /foo%23bar become /foo#bar.
The result is that URL's cannot safely be passed around through search parameters, because tanstack will not preserve the value.
The encoding for the first link is: ?continueUrl=%2Ffoo%2523bar
The encoding for the second link is: ?continueUrl=%2Ffoo%23bar
So for some reason TSR is double decoding in the first case when it should just decode once.
Expected behavior
As a user, I expect to see my search param value to be retained. Clicking on the first link should display: { "continueUrl": "/foo%23bar"} instead of { "continueUrl": "/foo#bar"}.
Since mix has already come from URLSearchParams, it has already been URL decoded. this code decodes it again which I'm sure helps in cases where users (or the library itself) accidentally double-encode something, but it's responsible for this behavior.
Activity
djrenren commentedon May 30, 2025
I believe the issue is here:
router/packages/router-core/src/qss.ts
Lines 47 to 49 in c0a6050
Since
mixhas already come fromURLSearchParams, it has already been URL decoded. this code decodes it again which I'm sure helps in cases where users (or the library itself) accidentally double-encode something, but it's responsible for this behavior.djrenren commentedon Jun 3, 2025
Confirmed fixed
v1.120.15. ty @vcarel