fix(multipart): accept exactly maxParts parts (#118)
busboy emits `partsLimit` once its part count reaches `limits.parts`, not when it passes it, and parseMultipart treats that event as a malformed body. With `maxParts: N` a body of exactly N parts was therefore rejected with 400 and only N-1 were accepted. parseMultipart now passes `maxParts + 1` to busboy, the same one-unit headroom it already gives `fieldSize`. N parts are accepted, N+1 are rejected. Route-level and server-level maxParts share this path, as do the Node server and app.fetch. test/multipart.test.ts adds the exact-N case on parseMultipart; test/multipart-http.test.ts sends exactly N parts at route and server level. All three new assertions fail without the fix. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
4 files changed
+18
-1
No files matched your search
@@ -79,6 +79,12 @@ describe('parseMultipart', () => {
|
||||
await expect(parseMultipart(b, B, { maxParts: 2, duplicates: 'last' })).rejects.toThrow();
|
||||
});
|
||||
|
||||
// Gitea #118: busboy signals the limit when the count reaches it, which used to reject exactly N.
|
||||
it('exactly maxParts parts → accepted', async () => {
|
||||
const b = body([field('a', '1'), field('b', '2')]);
|
||||
expect((await parseMultipart(b, B, { maxParts: 2, duplicates: 'last' })).fields).toEqual({ a: '1', b: '2' });
|
||||
});
|
||||
|
||||
// GitHub #39: busboy cuts a field at its size limit and only flags it, so the parser has to refuse
|
||||
// the body rather than hand the handler partial data.
|
||||
it('a field over maxFieldBytes → rejects with 413 instead of truncating', async () => {
|
||||
|
||||
Reference in new issue
Block a user