Skip to content

Commit

Permalink
Fix proxying non-ASCII (coder#6154)
Browse files Browse the repository at this point in the history
This only affects the path proxy since `req.originalUrl` is in escaped format.
  • Loading branch information
smalllady authored Apr 25, 2023
1 parent 2e17735 commit 951d8ac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/node/routes/pathProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions test/unit/node/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 951d8ac

Please sign in to comment.