forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: generatePath incorrectly applying parameters remix-run#9051
generatePath was doing multiple passes on the `path` using string replace, the first two passes were applying parameters, the third pass was doing a cleanup and the fourth path was applying the `splat`. It was possible to get incorrect results while applying `splat` when the last parameter value ended with `*`: ```ts const path = generatePath("/route/:name", { name: encodeURIComponent("includes *asterisk at the end*"), }) ``` ``` Expected: "/route/includes *asterisk at the end*" Received: "/route/includes *asterisk at the end" ``` results of the first two passes return the value of `/route/*asterisk at the end*` which was later treated as path with the splat resulting in the last asterisk removed. it was also possible to inject the splat value unintentionally ```ts generatePath("/courses/:name", { name: "foo*", "*": "splat_should_not_be_added" }) ``` ``` Expected: "/courses/foo*" Received: "/courses/foosplat_should_not_be_added" ``` A safer option, instead of mutating a global path multiple times, is to split the path into segments, process each segment in isolation and then join them back together. fixes remix-run#9051
- Loading branch information
Showing
5 changed files
with
65 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"react-router": patch | ||
--- | ||
|
||
Fix `generatePath` incorrectly applying parameters in some cases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,7 @@ | |
- ms10596 | ||
- ned-park | ||
- noisypigeon | ||
- Obi-Dann | ||
- omar-moquete | ||
- p13i | ||
- parched | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters