Closed
Description
What version of React Router are you using?
6.15.0
Steps to Reproduce
- With the route
/web/:param
and the stringa#b%c
- Encode the string with
encodeURIComponent
and navigate to the path/web/a%23b%25c
- Get the param with
useParams()
- The value should match the original string, instead it becomes
a%23b%c
- A partially decoded version of the string
Expected Behavior
Any segment in a pathname correctly encoded with encodeURIComponent
should be decoded back the same way
Actual Behavior
The param is decoded twice:
- First with
safelyDecodeURI(pathname)
inmatchRoutes
- This results in a partially decoded value sincedecodeURI
decodes less characters thandecodeURIComponent
- Then the partially decoded value is decoded again with
safelyDecodeURIComponent
inmatchPath
causing it to fail as the url segment is malformed because of the previous decoding.