Skip to content
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]: encoded percentages in pathname get incorrectly decoded within router's navigate(obj) #10213

Open
jamescazzetta opened this issue Mar 16, 2023 · 2 comments
Labels

Comments

@jamescazzetta
Copy link

jamescazzetta commented Mar 16, 2023

What version of React Router are you using?

6.8.0

Steps to Reproduce

I am using createBrowserRouter to prohibit certain calls from happening, and when I do

	const router = createBrowserRouter([
		{
			path: '*',
			element
		}
	]);
	
	const _navigate = router.navigate.bind(router);
	
	router.navigate = (to, opts) => {
		const allowed = true
		if (!allowed) return null;
		return _navigate(to, opts);
	};
	return <RouterProvider router={router} />;

To reproduce, pass an object to to like the following:
{ pathname: 'ABC/TEST%257FAB' }

the percentage in the pathname is encoded (%25) and it seems that the component being initialized ends up with incorrect props.params.

Expected Behavior

{
    "params": {
        "*": "ABC/TEST%257FAB",
        "id": "ABC/TEST%257FAB"
    },
    "location": {
        "pathname": "/ABC/TEST%257FAB",
        "search": "",
        "hash": "",
        "state": null,
        "key": "gqcl35xw"
    }
}

Actual Behavior

{
    "params": {
        "*": "ABC/TEST�AB",
        "id": "TEST�AB"
    },
    "location": {
        "pathname": "/ABC/TEST%257FAB",
        "search": "",
        "hash": "",
        "state": null,
        "key": "gqcl35xw"
    }
}
@jamescazzetta
Copy link
Author

Also linking this past ticket here as I think it's related:

The general question that arises is, do you support escaped percentages as path names, or, why wouldn't you support them? As far as I understand, it is totally a valid character (if escaped) or am I wrong here?

@jamescazzetta jamescazzetta changed the title [Bug]: encoded percentages in pathname get falsely decoded router's navigate(obj) [Bug]: encoded percentages in pathname get incorrectly decoded within router's navigate(obj) Mar 16, 2023
@DavidHenri008
Copy link

I am also having the issue.
In my case, the url is formed with the pattern /user/:userId.
The userId has a value of %a.
When encoded in the url I have /user/%25a.
This generates an error because react-router seems to decode it twice meaning it does a first pass and obtains /user/%a then it does it a second time and it fails because %a is, of course, a bad encoding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants