Skip to content

Commit 5e04b09

Browse files
committed
test(integration): bug-report - param containing forward slash encoded with encodeURIComponent should not be decoded by useParams/matchPath
1 parent b1c2e15 commit 5e04b09

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

integration/bug-report-test.ts

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,22 @@ test.beforeAll(async () => {
6464
// `createFixture` will make an app and run your tests against it.
6565
////////////////////////////////////////////////////////////////////////////
6666
files: {
67-
"app/routes/_index.tsx": js`
68-
import { useLoaderData, Link } from "react-router";
67+
"app/routes/use-params.$id.tsx": js`
68+
import { useParams } from "react-router";
6969
70-
export function loader() {
71-
return "pizza";
72-
}
73-
74-
export default function Index() {
75-
let data = useLoaderData();
76-
return (
77-
<div>
78-
{data}
79-
<Link to="/burgers">Other Route</Link>
80-
</div>
81-
)
70+
export default function ItemPage() {
71+
let params = useParams();
72+
return <div data-testid="item-id">Item ID: {params.id}</div>;
8273
}
8374
`,
8475

85-
"app/routes/burgers.tsx": js`
86-
export default function Index() {
87-
return <div>cheeseburger</div>;
76+
"app/routes/match-path.$id.tsx": js`
77+
import { matchPath, useLocation } from "react-router";
78+
79+
export default function ItemPage() {
80+
const location = useLocation()
81+
const match = matchPath({ path: '/match-path/:id' }, location.pathname)
82+
return <div data-testid="item-id">Item ID: {match.params.id}</div>;
8883
}
8984
`,
9085
},
@@ -103,22 +98,24 @@ test.afterAll(() => {
10398
// add a good description for what you expect React Router to do 👇🏽
10499
////////////////////////////////////////////////////////////////////////////////
105100

106-
test("[description of what you expect it to do]", async ({ page }) => {
101+
test("useParams should not decode param containing double-encoded forward slash", async ({
102+
page,
103+
}) => {
107104
let app = new PlaywrightFixture(appFixture, page);
108-
// You can test any request your app might get using `fixture`.
109-
let response = await fixture.requestDocument("/");
110-
expect(await response.text()).toMatch("pizza");
111-
112-
// If you need to test interactivity use the `app`
113-
await app.goto("/");
114-
await app.clickLink("/burgers");
115-
await page.waitForSelector("text=cheeseburger");
116-
117-
// If you're not sure what's going on, you can "poke" the app, it'll
118-
// automatically open up in your browser for 20 seconds, so be quick!
119-
// await app.poke(20);
105+
const encodedId = encodeURIComponent(encodeURIComponent("beforeslash/afterslash@"));
106+
await app.goto(`/use-params/${encodedId}`);
107+
let el = page.locator("[data-testid='item-id']");
108+
await expect(el).toHaveText(`Item ID: ${encodedId}`);
109+
});
120110

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

124121
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)