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:
@@ -649,7 +649,7 @@ describe("Batch edge cases — extended", () => {
|
||||
// Should succeed and deduplicate filenames in the ZIP
|
||||
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));
|
||||
// All three entries should have unique names
|
||||
const names = Object.values(fileResults);
|
||||
expect(new Set(names).size).toBe(3);
|
||||
@@ -1524,7 +1524,7 @@ describe("Batch limits — boundary tests", () => {
|
||||
|
||||
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(1);
|
||||
});
|
||||
|
||||
@@ -1546,7 +1546,7 @@ describe("Batch limits — boundary tests", () => {
|
||||
|
||||
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(10);
|
||||
}, 120_000);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user