Skip to content

Percent (%) in routes params break the application due to encoding/decoding issue #7225

@kopax

Description

@kopax

I have the following route:

    path: '/article/:title--:id.html',

This is my params

{ id: 10 , title: '-50% on nutella' }

It fail to encode the percent, or it fail to decode if I encode it myself the title with encoreURIComponent or encoreURI

Version

  • react-router 5.1.2
  • react-router-dom 5.1.2

Steps to reproduce

Use history.push(page, { id: 1, title: '-50%' })

  • Notice that it fail to encode

Use history.push(page, { id: 1, title: encodeURIComponent('-50%') })

  • Notice that it now work

  • Press F5, notice that it can't decode

  • Notice that it fail to encode

Expected Behavior

I expect RR to be able to encode and decode any characters

Actual Behavior

It fail to encode the %

 URIError: Pathname "/article/-50%--13.html" could not be decoded. This is likely caused by an invalid percent-encoding.
    at createLocation (history.js:87)

With encodeURIComponent(title), on refresh (F5)

But then a decode does: URIError: Failed to decode param '/article/-50%--14.html'
    at decodeURIComponent (<anonymous>)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions