Skip to content

Commit

Permalink
Redirects when multiple slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
“ErimTuzcuoglu” committed Nov 16, 2022
1 parent aa8a9e2 commit fadbd0d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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
3 changes: 3 additions & 0 deletions packages/remix-express/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ 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

0 comments on commit fadbd0d

Please sign in to comment.