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
@@ -147,6 +147,7 @@ describe('multipart limits on app.fetch (#105)', () => {
|
||||
@Module({ mountpoint: '/', controllers: [C] }) class CMod {}
|
||||
app = createApp({ modules: [CMod] });
|
||||
|
||||
expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(2) }))).status).toBe(200); // #118
|
||||
const r = await app.fetch(new Request('http://x/u', { method: 'POST', body: form(3) }));
|
||||
|
||||
expect(r.status).toBe(400);
|
||||
@@ -175,6 +176,7 @@ describe('multipart limits on app.fetch (#105)', () => {
|
||||
app = createApp({ modules: [CMod], limits: { maxParts: 2 } });
|
||||
|
||||
expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(1) }))).status).toBe(200);
|
||||
expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(2) }))).status).toBe(200);
|
||||
expect((await app.fetch(new Request('http://x/u', { method: 'POST', body: form(3) }))).status).toBe(400);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user