From 951d8ac45ef20cab60af84932369ded905e1a51b Mon Sep 17 00:00:00 2001 From: smalllady <33916586+smalllady@users.noreply.github.com> Date: Wed, 26 Apr 2023 03:41:33 +0800 Subject: [PATCH] Fix proxying non-ASCII (#6154) This only affects the path proxy since `req.originalUrl` is in escaped format. --- src/node/routes/pathProxy.ts | 2 +- test/unit/node/proxy.test.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/node/routes/pathProxy.ts b/src/node/routes/pathProxy.ts index f574a4494..6d3c067e1 100644 --- a/src/node/routes/pathProxy.ts +++ b/src/node/routes/pathProxy.ts @@ -11,7 +11,7 @@ const getProxyTarget = (req: Request, passthroughPath?: boolean): string => { return `http://0.0.0.0:${req.params.port}/${req.originalUrl}` } const query = qs.stringify(req.query) - return `http://0.0.0.0:${req.params.port}/${req.params[0] || ""}${query ? `?${query}` : ""}` + return encodeURI(`http://0.0.0.0:${req.params.port}${req.params[0] || ""}${query ? `?${query}` : ""}`) } export async function proxy( diff --git a/test/unit/node/proxy.test.ts b/test/unit/node/proxy.test.ts index 9502c9429..ea124e4f2 100644 --- a/test/unit/node/proxy.test.ts +++ b/test/unit/node/proxy.test.ts @@ -187,6 +187,17 @@ describe("proxy", () => { }) }).rejects.toThrow() }) + + it("should proxy non-ASCII", async () => { + e.get("*", (req, res) => { + res.json("ほげ") + }) + codeServer = await integration.setup(["--auth=none"], "") + const resp = await codeServer.fetch(proxyPath.replace("wsup", "ほげ")) + expect(resp.status).toBe(200) + const json = await resp.json() + expect(json).toBe("ほげ") + }) }) // NOTE@jsjoeio