Skip to content

Commit a4e4317

Browse files
committed
fix: request creation when double slashes exist
@see: remix-run/remix#5336 Signed-off-by: Logan McAnsh <logan@mcan.sh>
1 parent 27e3bf1 commit a4e4317

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

packages/remix-fastify/__tests__/index.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,32 @@ describe("fastify createRequestHandler", () => {
6666
expect(response.body).toBe("URL: /foo/bar");
6767
});
6868

69+
it("handles root // URLs", async () => {
70+
mockedCreateRequestHandler.mockImplementation(() => async (req) => {
71+
return new Response("URL: " + new URL(req.url).pathname);
72+
});
73+
74+
let app = createApp();
75+
76+
let response = await app.inject("//");
77+
78+
expect(response.statusCode).toBe(200);
79+
expect(response.body).toBe("URL: //");
80+
});
81+
82+
it("handles nested // URLs", async () => {
83+
mockedCreateRequestHandler.mockImplementation(() => async (req) => {
84+
return new Response("URL: " + new URL(req.url).pathname);
85+
});
86+
87+
let app = createApp();
88+
89+
let response = await app.inject("//foo//bar");
90+
91+
expect(response.statusCode).toBe(200);
92+
expect(response.body).toBe("URL: //foo//bar");
93+
});
94+
6995
it("handles null body", async () => {
7096
mockedCreateRequestHandler.mockImplementation(() => async () => {
7197
return new Response(null, { status: 200 });

packages/remix-fastify/src/server.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function createRemixHeaders(
8383

8484
export function createRemixRequest(request: FastifyRequest): NodeRequest {
8585
let origin = `${request.protocol}://${request.hostname}`;
86-
let url = new URL(request.url, origin);
86+
let url = `${origin}${request.url}`;
8787

8888
let controller = new AbortController();
8989

@@ -97,7 +97,7 @@ export function createRemixRequest(request: FastifyRequest): NodeRequest {
9797
init.body = request.raw;
9898
}
9999

100-
return new NodeRequest(url.href, init);
100+
return new NodeRequest(url, init);
101101
}
102102

103103
export async function sendRemixResponse(

0 commit comments

Comments
 (0)