|
1 | 1 | 'use strict' |
2 | 2 |
|
| 3 | +const { spawnSync } = require('node:child_process') |
| 4 | +const { test } = require('node:test') |
3 | 5 | const Multipart = require('../lib/types/multipart') |
4 | 6 | const Busboy = require('..') |
5 | | -const { test } = require('node:test') |
6 | 7 |
|
7 | | -test('multipart constructor', t => { |
8 | | - t.plan(1) |
| 8 | +test('multipart constructor', async t => { |
| 9 | + t.plan(2) |
9 | 10 |
|
10 | | - t.test('throws if the boundary is not a string', t => { |
| 11 | + await t.test('throws if the boundary is not a string', t => { |
11 | 12 | const busboy = new Busboy({ headers: { 'content-type': 'application/x-www-form-urlencoded' } }) |
12 | 13 |
|
13 | 14 | t.assert.throws(() => new Multipart(busboy, { boundary: 123 }), { message: 'Multipart: Boundary not found' }) |
14 | 15 | t.assert.ok('end') |
15 | 16 | }) |
| 17 | + |
| 18 | + await t.test('processes a fragmented 252-byte boundary without hanging', t => { |
| 19 | + t.plan(1) |
| 20 | + |
| 21 | + const script = ` |
| 22 | + const Busboy = require(${JSON.stringify(require.resolve('..'))}) |
| 23 | + const boundary = 'A'.repeat(252) |
| 24 | + const parser = Busboy({ |
| 25 | + headers: { 'content-type': 'multipart/form-data; boundary=' + boundary } |
| 26 | + }) |
| 27 | + parser.write(Buffer.from('--' + boundary.slice(0, -1))) |
| 28 | + parser.write(Buffer.from('X'), (error) => process.exit(error ? 1 : 0)) |
| 29 | + setTimeout(() => process.exit(1), 500) |
| 30 | + ` |
| 31 | + const result = spawnSync(process.execPath, ['-e', script], { timeout: 2000 }) |
| 32 | + |
| 33 | + t.assert.deepStrictEqual( |
| 34 | + { error: result.error && result.error.code, signal: result.signal, status: result.status }, |
| 35 | + { error: undefined, signal: null, status: 0 } |
| 36 | + ) |
| 37 | + }) |
16 | 38 | }) |
0 commit comments