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

fix: generatePath incorrectly applying parameters #9051 #10078

Merged
merged 3 commits into from Mar 3, 2023

Commits on Feb 9, 2023

  1. 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
    Obi-Dann committed Feb 9, 2023
    Configuration menu
    Copy the full SHA
    4440090 View commit details
    Browse the repository at this point in the history
  2. fix: incorrect typings for PathParam when path is /*

    paramName for the splat wasn't correctly resolved when the pas is `/*`
    Obi-Dann committed Feb 9, 2023
    Configuration menu
    Copy the full SHA
    eef790c View commit details
    Browse the repository at this point in the history

Commits on Mar 3, 2023

  1. Configuration menu
    Copy the full SHA
    3e63bd0 View commit details
    Browse the repository at this point in the history