Skip to content

[Bug]: params encoded with encodeURIComponent incorrectly decoded if they contain % and other special characters #10814

Closed
@dstaver

Description

@dstaver

What version of React Router are you using?

6.15.0

Steps to Reproduce

  1. With the route /web/:param and the string a#b%c
  2. Encode the string with encodeURIComponent and navigate to the path /web/a%23b%25c
  3. Get the param with useParams()
  4. 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:

  1. First with safelyDecodeURI(pathname) in matchRoutes - This results in a partially decoded value since decodeURI decodes less characters than decodeURIComponent
  2. Then the partially decoded value is decoded again with safelyDecodeURIComponent in matchPath causing it to fail as the url segment is malformed because of the previous decoding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions