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

Redirects when multiple slashes #4622

Closed
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 @@ -119,6 +119,7 @@
- eldarshamukhamedov
- emzoumpo
- eps1lon
- ErimTuzcuoglu
- esamattis
- evanwinter
- exegeteio
Expand Down
12 changes: 12 additions & 0 deletions packages/remix-express/__tests__/server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ describe("express createRequestHandler", () => {
expect(res.headers["x-powered-by"]).toBe("Express");
});

it("redirects when multiple slashes", async () => {
mockedCreateRequestHandler.mockImplementation(() => async (req) => {
return new Response(`${new URL(req.url).pathname}`);
});

let request = supertest(createApp());
let res = await request.get("//foo///bar///");

expect(res.status).toBe(302);
expect(res.text).toBe("Found. Redirecting to /foo/bar/");
});

it("handles null body", async () => {
mockedCreateRequestHandler.mockImplementation(() => async () => {
return new Response(null, { status: 200 });
Expand Down
5 changes: 5 additions & 0 deletions packages/remix-express/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export function createRequestHandler({
next: express.NextFunction
) => {
try {
let cleanUrl = req.url.replace(/\/+/g, '/');
if (req.url !== cleanUrl) {
return res.redirect(cleanUrl);
}

let request = createRemixRequest(req, res);
let loadContext = getLoadContext?.(req, res);

Expand Down