-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[Bug]: params encoded with encodeURIComponent incorrectly decoded if they contain % and other special characters #10814
Comments
We were facing the same issue, here is how we solved it:
Nothing breaks and everything works like we want it. |
As I outlined in the duplicate issue that I opened, I believe this can be fixed by using |
I've got a PR up to fix this in in #11199 but since path matching and encoding is such a tricky subject I'd love for a few folks to help alpha test the new approach 🙌 I cut an experimental release with those changes - if anyone (OP or other) could test their specific scenario and let me know if it's fixed that would be super helpful in knowing we've got the right fix.
I've also added the OP issue and the issue reported in #11179 to this code sandbox using the experimental release and things look good there: https://codesandbox.io/p/sandbox/billowing-fast-hv6v4v?file=%2Fsrc%2Findex.js%3A11%2C18 |
@brophdawg11 This does appear to fix the route matching issue, however the |
@RobinClowers Thanks for confirming! And yeah I would expect newlines to still have issues - we can keep #11146 for issues related to newlines 👍 |
Oh sorry, I meant to say stripping whitespace, not newlines. My test case was a path segment with spaces on either side of it, and it appears that something is trimming off the trailing whitespace, which breaks my routing. |
@RobinClowers Could you fork and add your scenario to this sandbox (which is using the above experimental version)? It looks like spaces on both sides is OK so I might not have the right reproduction: https://codesandbox.io/p/sandbox/zealous-dawn-q8xwyt?file=%2Fsrc%2Findex.js%3A44%2C27 |
Sure thing: https://codesandbox.io/p/sandbox/mutable-framework-4l8645. It looks like it's |
Ah ok thank you for the repro 🙌 . I just pushed a fix for that in #11199 and released a new experimental: |
@brophdawg11 thanks again for being so responsive here, the latest fix resolves all my issues other than the newline issue! |
Fixed via #11199 - will be included in the next release |
🤖 Hello there, We just published version Thanks! |
Just tried out the pre-release, looks good! |
🤖 Hello there, We just published version Thanks! |
Hi, would it be possible to have the v5 version updated with this fix as well? |
Any updates on the fix being added to the router v5 ? |
AFAIK, we're no longer making changes to v5 (short of critical security vulnerabilities). Is there anything in particular keeping you from upgrading to v6? |
What version of React Router are you using?
6.15.0
Steps to Reproduce
/web/:param
and the stringa#b%c
encodeURIComponent
and navigate to the path/web/a%23b%25c
useParams()
a%23b%c
- A partially decoded version of the stringExpected Behavior
Any segment in a pathname correctly encoded with
encodeURIComponent
should be decoded back the same wayActual Behavior
The param is decoded twice:
safelyDecodeURI(pathname)
inmatchRoutes
- This results in a partially decoded value sincedecodeURI
decodes less characters thandecodeURIComponent
safelyDecodeURIComponent
inmatchPath
causing it to fail as the url segment is malformed because of the previous decoding.The text was updated successfully, but these errors were encountered: