fix: import Transform from node:stream to fix ReferenceError on unencoded requests#1069
Open
guoyangzhen wants to merge 3 commits intonode-formidable:masterfrom
Open
fix: import Transform from node:stream to fix ReferenceError on unencoded requests#1069guoyangzhen wants to merge 3 commits intonode-formidable:masterfrom
guoyangzhen wants to merge 3 commits intonode-formidable:masterfrom
Conversation
Fixes node-formidable#987 When maxFiles limit is reached, the fileBegin event handler calls _error(), but _handlePart continues and opens a write stream for the new file. These file handles are never closed. Fix: check this.error after emitting fileBegin and before file.open(). If an error occurred (e.g., maxFiles exceeded), decrement _flushing and return early to prevent the file stream from being opened.
…oded requests Fixes node-formidable#1063 The compression support switch (commit 1a7f4a9) references in the default case, but is never imported. Every request without a Content-Encoding header throws . Changes: - Add - Use instead of
The module uses 'type': "module" in package.json, so require() is not
available. Replace all require('zlib') calls with proper ESM imports
(createGunzip, createInflate, createBrotliDecompress, createUnzip).
This fixes node-formidable#1063 more completely:
- The node_stream Transform import from previous commit fixes the
ReferenceError for uncompressed requests
- This commit fixes ReferenceError: require is not defined for
compressed requests (gzip, deflate, br, compress)
Contributor
|
could we merge existing PR before creating new ones ? |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1063
Problem
Commit
1a7f4a9introduced compression support with a switch onthis.headers["content-encoding"]insrc/Formidable.js. This has two ESM-breaking bugs:node_stream.Transform()butnode_streamis never imported →ReferenceErrorrequire("zlib")in an ESM module (package.json has"type": "module") →ReferenceError: require is not definedEvery real-world multipart upload without
Content-Encodingheader hits case #1. Every compressed request hits case #2.Fix
import { Transform } from "node:stream"and changednode_stream.Transform({...})tonew Transform({...})require("zlib").createXxx()calls with proper ESM imports:import { createGunzip, createInflate, createBrotliDecompress, createUnzip } from "node:zlib"Testing
Verified the imports are valid ESM by checking
node:zlibandnode:streamexport these functions in Node.js 18+.