Skip to content

params encoded with encodeURIComponent incorrectly decoded for relative paths if they contain # #13089

@SangJunBak

Description

@SangJunBak

I'm using React Router as a...

library

Reproduction

Version: react-router-dom 6.27.0
Sandbox: https://codesandbox.io/p/devbox/mutable-framework-4l8645-forked-vq3pdx

Steps to reproduce:

  1. Go to the sandbox and click nested path with a'bc\d/e#f//g_
Image
  1. Notice how we show "whatever - name: "a'bcd/e#f//g_"
Image
  1. Click "relative link after surrounding spaces: whatever" which is defined as <Link to="./whatever">. Notice how the URL changes from https://vq3pdx.csb.app/foos/foo/a'bcd%2Fe%23f%2F%2Fg_/whatever to https://vq3pdx.csb.app/foos/foo/a'bcd%2Fe/whatever
Image

System Info

System:
  OS: macOS 15.3.1
  CPU: (10) arm64 Apple M1 Max
  Memory: 1.56 GB / 64.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 18.18.0 - /usr/local/bin/node
  Yarn: 4.3.1 - /opt/homebrew/bin/yarn
  npm: 9.8.1 - /opt/homebrew/bin/npm
  pnpm: 8.13.1 - /opt/homebrew/bin/pnpm
Browsers:
  Brave Browser: 118.1.59.117
  Chrome: 133.0.6943.127
  Edge: 133.0.3065.69
  Safari: 18.3
npmPackages:
  vite: ^6.0.11 => 6.0.11

Used Package Manager

yarn

Expected Behavior

In step 3 of steps to reproduction, the URL should be https://vq3pdx.csb.app/foos/foo/a'bcd%2Fe%23f%2F%2Fg_/whatever

Actual Behavior

The URL becomes https://vq3pdx.csb.app/foos/foo/a'bcd%2Fe/whatever. Interestingly enough, if you remove the hashtag from the URI component a'bc\d/ef//g_, you get the correct behavior

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions