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:
SnapOtter
2026-05-12 23:19:20 +08:00
parent 8c1526559b
commit ac8c585beb
13 changed files with 132 additions and 21 deletions
+2 -2
View File
@@ -1035,7 +1035,7 @@ describe("Batch -- all identical files", () => {
expect(res.statusCode).toBe(200);
expect(res.headers["content-type"]).toBe("application/zip");
const fileResults = JSON.parse(res.headers["x-file-results"] as string);
const fileResults = JSON.parse(decodeURIComponent(res.headers["x-file-results"] as string));
expect(Object.keys(fileResults).length).toBe(5);
});
@@ -1050,7 +1050,7 @@ describe("Batch -- all identical files", () => {
expect(res.statusCode).toBe(200);
expect(res.headers["content-type"]).toBe("application/zip");
const fileResults = JSON.parse(res.headers["x-file-results"] as string);
const fileResults = JSON.parse(decodeURIComponent(res.headers["x-file-results"] as string));
const names = Object.values(fileResults);
// All three entries should have unique names in the ZIP
expect(new Set(names).size).toBe(3);