Skip to content

bug-report - param containing double encoded characters should not be double decoded by useParams #13813

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
- pruszel
- pwdcd
- pyitphyoaung
- qtoden
- refusado
- renyu-io
- reyronald
Expand Down
59 changes: 28 additions & 31 deletions integration/bug-report-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,22 @@ test.beforeAll(async () => {
// `createFixture` will make an app and run your tests against it.
////////////////////////////////////////////////////////////////////////////
files: {
"app/routes/_index.tsx": js`
import { useLoaderData, Link } from "react-router";
"app/routes/use-params.$id.tsx": js`
import { useParams } from "react-router";

export function loader() {
return "pizza";
}

export default function Index() {
let data = useLoaderData();
return (
<div>
{data}
<Link to="/burgers">Other Route</Link>
</div>
)
export default function ItemPage() {
let params = useParams();
return <div data-testid="item-id">Item ID: {params.id}</div>;
}
`,

"app/routes/burgers.tsx": js`
export default function Index() {
return <div>cheeseburger</div>;
"app/routes/match-path.$id.tsx": js`
import { matchPath, useLocation } from "react-router";

export default function ItemPage() {
const location = useLocation()
const match = matchPath({ path: '/match-path/:id' }, location.pathname)
return <div data-testid="item-id">Item ID: {match.params.id}</div>;
}
`,
},
Expand All @@ -103,22 +98,24 @@ test.afterAll(() => {
// add a good description for what you expect React Router to do 👇🏽
////////////////////////////////////////////////////////////////////////////////

test("[description of what you expect it to do]", async ({ page }) => {
test("useParams should not decode param containing double-encoded forward slash", async ({
page,
}) => {
let app = new PlaywrightFixture(appFixture, page);
// You can test any request your app might get using `fixture`.
let response = await fixture.requestDocument("/");
expect(await response.text()).toMatch("pizza");

// If you need to test interactivity use the `app`
await app.goto("/");
await app.clickLink("/burgers");
await page.waitForSelector("text=cheeseburger");

// If you're not sure what's going on, you can "poke" the app, it'll
// automatically open up in your browser for 20 seconds, so be quick!
// await app.poke(20);
const encodedId = encodeURIComponent(encodeURIComponent("beforeslash/afterslash@"));
await app.goto(`/use-params/${encodedId}`);
let el = page.locator("[data-testid='item-id']");
await expect(el).toHaveText(`Item ID: ${encodedId}`);
});

// Go check out the other tests to see what else you can do.
test("matchPath should not decode param containing double-encoded forward slash", async ({
page,
}) => {
let app = new PlaywrightFixture(appFixture, page);
const encodedId = encodeURIComponent(encodeURIComponent("beforeslash/afterslash@"));
await app.goto(`/match-path/${encodedId}`);
let el = page.locator("[data-testid='item-id']");
await expect(el).toHaveText(`Item ID: ${encodedId}`);
});

////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading