From 90cc859a69fa6405f943533681a7f83bc6926ecc Mon Sep 17 00:00:00 2001 From: smalllady <33916586+smalllady@users.noreply.github.com> Date: Thu, 20 Apr 2023 11:10:46 +0800 Subject: [PATCH 1/3] Update pathProxy.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix:预览包含中文字符命名的html文件,无法正常预览 --- src/node/routes/pathProxy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/routes/pathProxy.ts b/src/node/routes/pathProxy.ts index f574a4494548..39ae6a4e268e 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( From a7abb79bda744b1d67ddd275d38a8c92b3cc3e71 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 25 Apr 2023 11:04:30 -0800 Subject: [PATCH 2/3] Add a test for non-ASCII path proxy --- test/unit/node/proxy.test.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/unit/node/proxy.test.ts b/test/unit/node/proxy.test.ts index 9502c9429cd1..ea124e4f2b90 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 From 3d244f8398f4a95f8a917cb1fcbcf62ed5b63315 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 25 Apr 2023 11:04:52 -0800 Subject: [PATCH 3/3] Remove semicolon --- src/node/routes/pathProxy.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node/routes/pathProxy.ts b/src/node/routes/pathProxy.ts index 39ae6a4e268e..6d3c067e1f58 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 encodeURI(`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(