mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: percent-encode X-File-Results header to support non-ASCII filenames
The X-File-Results header contained raw JSON with non-ASCII characters from filenames (Chinese, Japanese, etc.), violating RFC 7230. Node.js threw ERR_INVALID_CHAR on writeHead(). Fixed by wrapping the JSON in encodeURIComponent() on the backend and decodeURIComponent() on the frontend, ensuring only ASCII goes into the header while preserving the original filenames after decoding. Closes #133
This commit is contained in:
@@ -426,6 +426,33 @@ describe("Pipeline batch execution", () => {
|
||||
expect(res.headers["x-file-results"]).toBeDefined();
|
||||
});
|
||||
|
||||
it("handles non-ASCII filenames without ERR_INVALID_CHAR (#133)", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "图片.png", contentType: "image/png", content: PNG_200x150 },
|
||||
{ name: "file", filename: "写真テスト.png", contentType: "image/png", content: PNG_200x150 },
|
||||
{
|
||||
name: "pipeline",
|
||||
content: JSON.stringify({
|
||||
steps: [{ toolId: "resize", settings: { width: 50 } }],
|
||||
}),
|
||||
},
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/pipeline/batch",
|
||||
headers: { "content-type": contentType, authorization: `Bearer ${adminToken}` },
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
const raw = res.headers["x-file-results"] as string;
|
||||
expect(raw).not.toMatch(/[-]/);
|
||||
const fileResults = JSON.parse(decodeURIComponent(raw));
|
||||
expect(fileResults["0"]).toContain("图片");
|
||||
expect(fileResults["1"]).toContain("写真テスト");
|
||||
});
|
||||
|
||||
it("rejects pipeline batch with no files", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user