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]: Nested routes under an id with a trailing = fail to match #8288

Closed
mikeldking opened this issue Nov 9, 2021 · 4 comments · Fixed by #8291
Closed

[Bug]: Nested routes under an id with a trailing = fail to match #8288

mikeldking opened this issue Nov 9, 2021 · 4 comments · Fixed by #8291
Labels

Comments

@mikeldking
Copy link
Contributor

mikeldking commented Nov 9, 2021

What version of React Router are you using?

6.0.0

Steps to Reproduce

Create a nested route

<Routes>
   <Route path="/dashboard/:dashboardId" element={<DashboardPage />}>
      <Route path="edit" element={<EditDasbhboard />}>
   </Route>
</Routes>

If the :dahboardId contains an equals sign at the end (e.x. a relay Id like RGFzaGJvYXJkOjE2MzU=), the generated regex ^\/dashboards\/([^\/]+)(?:\b|$) fails to capture the = at the end when the pathname is /dashboards/RGFzaGJvYXJkOjE2MzU=/edit

Expected Behavior

The generated regex that matches the :dashboardId should capture all the way up to the next forward slash.

Actual Behavior

pathname.match matches up to the = (/dashboards/RGFzaGJvYXJkOjE2MzU) but fails to capture the trailing =, causing the router to say that there are no matches for the nested route.

@mikeldking
Copy link
Contributor Author

mikeldking commented Nov 9, 2021

Here is an example of a failing test for a base64 encoded id (e.x. the output of graphql-relay's toGlobalId("User", "1"))
#8291

Happy to contribute back with a fix!

@mjackson
Copy link
Member

mjackson commented Nov 9, 2021

Thanks for the bug report. I think the correct regex should probably be ^\/dashboards\/([^\/]+)(?:\/|$) (look for the next / instead of a word boundary) but I'd have to test. Care to submit a PR?

@mikeldking
Copy link
Contributor Author

@mjackson Thank you so much for responding and giving me an opportunity to contribute!
Here is my PR: #8291

Slight modification to the regex you posted above. Passes all previous unit tests plus new ones for base64 encoded ids with trailing =s

@timdorr
Copy link
Member

timdorr commented Dec 10, 2021

This should be fixed in 6.1.0.

@timdorr timdorr closed this as completed Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants