-
-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: flush or fail always (don't hang) (#945)
* fix: flush or fail always (don't hang) * feat: more descriptive errors * tests: make test work when other tests are run * tests: add test to confirm issue
- Loading branch information
1 parent
489a0bb
commit 1699ec6
Showing
5 changed files
with
62 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {Readable} from 'node:stream'; | ||
import MultipartParser from '../../src/parsers/Multipart.js'; | ||
import {malformedMultipart} from '../../src/FormidableError.js'; | ||
|
||
import test from 'node:test'; | ||
import assert, { deepEqual } from 'node:assert'; | ||
|
||
|
||
|
||
test('MultipartParser does not hang', async (t) => { | ||
const mime = `--_\r\n--_--\r\n`; | ||
const parser = new MultipartParser(); | ||
parser.initWithBoundary('_'); | ||
try { | ||
for await (const {name, buffer, start, end} of Readable.from(mime).pipe(parser)) { | ||
console.log(name, buffer ? buffer.subarray(start, end).toString() : ''); | ||
} | ||
|
||
} catch (e) { | ||
deepEqual(e.code, malformedMultipart) | ||
return; | ||
// console.error('error'); | ||
// console.error(e); | ||
|
||
} | ||
assert(false, 'should catch error'); | ||
}); |