Repository navigation
fix(http): keep empty file names in multipart FormData parts - #11332
Dev-next-gen wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
[Medium impact] No outstanding findings block merging. The test now uses the shared HTTP server helpers and performs cleanup in SummaryFixes empty file names in multipart uploads through the Node HTTP adapter.
No new actionable issues were found in the changes since the previous review. No outstanding findings block merging. Reviews (2) · Last reviewed commit: "test(http): use the shared test server f..." · Reviewed by Greptile |
There was a problem hiding this comment.
PR #11332 - fix(http): keep empty file names in multipart FormData parts
Repo: axios/axios Author: @Dev-next-gen Base: v1.x Files: 3 **+34/-1
CI: Unavailable: no checks returned; no build/test workflow result is present in this snapshot. Mergeability: mergeable. Reviewed head: 5c48ef5da4df6ee486168375fc4f2f31a60bb79b.
Repo Profile
Axios is an npm JavaScript HTTP client for browsers and Node, with XHR/Fetch/HTTP adapters, default and named exports, interceptors, headers/errors, and paired ESM/CJS declarations. The target uses Vitest plus browser and package/module tests; v1 packaging covers older Node CJS runtimes as well as current ESM, Bun and Deno. Contributions preserve transport/security boundaries, add regression coverage and prerelease records, and defer unreleased user docs to PRE_RELEASE_DOCS.md. This review uses the actual target-branch guidance and files, not the separate local v0 checkout.
Verdict
Request changes — No concrete source defect found in this review; the missing latest-head validation prevent merge approval.
Posted as a comment review for the validation/integration hold; no formal code-change request is implied beyond the specific items below.
Change Explanation And User Impact
When a File has an empty name, formDataToStream omitted filename because it used a truthiness check. Multipart parsers then treated the part as a text field, losing its file identity and potentially corrupting binary bytes. The new string check includes filename="" while leaving unnamed non-file values on their existing path. Executed with a two-byte File named "": the current target was parsed as text; this head was parsed as a File with name "" and size 2. This affects Node HTTP multipart serialization, not the Fetch native serializer.
Validation scope: source/diff and regression-test review. Examples explicitly marked executed used isolated source snapshots on Node 24.18.0 with the workspace dependency installation; these were focused checks, not a clean install, full CI matrix, or full test-suite run. Author-reported test results were not treated as independently executed.
Competing PRs
Search: axios/axios open PRs, including drafts; full open-list scan plus FormData multipart in:title,body, filename in:title,body. Complementary searches were run across related APIs/issues; no query reached the 100-result cap and no search failed. The five explicitly excluded PRs were not reviewed or modified in this batch.
#11351 fixes native Fetch multipart headers; #11332 preserves empty filenames in the Node HTTP serializer. They operate at different boundaries and are complementary.
Preferred PR: No competing implementation supersedes this PR; continue it independently.
Unique contributions: The submitted regression cases protect this specific boundary; preserve them independently of adjacent fixes.
Action: No closure: the Fetch fix is complementary, and #11355 has an additional fallback-policy question and receiver coverage to consolidate.
A later open-set check also found #11355. It fixes the empty-name case but additionally assigns filename="blob" to unnamed/non-string values. This head preserves the existing unnamed-part behavior and asserts exact binary bytes; #11355 uses the existing HTTP multipart receiver. Keep both open until the fallback policy and useful receiver coverage are consolidated with attribution.
Project Fit
North star: Reliable HTTP transport and configuration across supported JavaScript environments, without embedding application-specific policy.
Benefits: Preserves empty-named binary uploads as files.
Tradeoffs: An empty filename remains a filename. Treating it as a string avoids inventing a replacement name or application upload policy.
Fit: Strong — The underlying problem belongs in the transport, serializer, declarations or their maintenance tests.
Adversarial Review
Strongest objection: An empty filename remains a filename. Treating it as a string avoids inventing a replacement name or application upload policy. Latest-head integration evidence is still needed.
Abuse/failure modes checked: Reviewed explicit empty names, normal names, binary contents and the serializer header construction; validated with an HTTP receiver parsing the actual multipart body.
Result: No concrete source defect established in the examined cases; validation and integration limits remain below.
Disposition
Continue
Address the specific blockers below; no unrelated scope or complementary PR should be closed.
Semver
patch — Corrects existing behavior or strengthens internal tooling/tests without adding a public API.
Breaking Changes
None intended beyond the bug correction described above; no public API removal or new runtime requirement is introduced by this diff.
Documentation
PRE_RELEASE_CHANGELOG.md records the change. No new API reference or migration is required for this scoped correction; keep the release description consistent with the behavior and limits above.
Performance And Regression Risk
Hot path touched: Yes — request/response processing or its shared helpers.
Performance concern: No unbounded new work identified in the changed path. An empty filename remains a filename. Treating it as a string avoids inventing a replacement name or application upload policy.
Regression risk: low — the changed boundary needs regression and integration coverage, particularly after any rebase.
Evidence requested: The latest-head checks listed below; no extra benchmark requested for this scoped change.
Blocking Issues
- Latest-head build/test validation is unavailable in the returned GitHub checks. Run or attach the repository build, relevant regression suite and required package/type/browser checks before merge; review/security bots alone do not establish that they pass. This is a validation hold, not an invented source defect.
Non-Blocking Suggestions
- Retain the binary receiver assertion in future refactors; a header-only assertion would not demonstrate preservation of file semantics.
Looks Good
- Reviewed explicit empty names, normal names, binary contents and the serializer header construction; validated with an HTTP receiver parsing the actual multipart body.
Summary
With the Node http adapter, a native
FormDatafile appended with an empty name (form.append('upload', blob, '')) is written without afilenameparameter, becauseformDataToStreamonly adds it whenvalue.nameis truthy. The part still gets aContent-Type, but multipart parsers read a part withoutfilenameas a text field: the server receives a string, and binary content is decoded as UTF-8 (ff 00arrives as'�\^@'). The fetch path's own serializer,formDataToBlob, already writesfilename=""for this entry, andformBodyLengthCasesexpects the parsed upload to come back as a file named''.The fix writes
filenamewhenever the entry'snameis a string, so an empty name givesfilename="". Blob-like values without anameproperty keep the old output; a blob-like value with a non-stringname(e.g.123) no longer gets afilenameparameter.Linked issue
Fixes #11331
Changes
lib/helpers/formDataToStream.js: checkutils.isString(value.name)instead of truthiness before writingfilename.tests/unit/helpers/formDataToStream.test.js: posts a nativeFormDatawith an empty-named file throughaxios.postand the http adapter to a local server, then parses the received body withResponse.formData().PRE_RELEASE_CHANGELOG.md: Bug Fixes entry.Validation
All commands ran in a
node:22-bookwormcontainer (Node 22) afternpm ci --ignore-scripts, with no network during the test phase.npx vitest run --project unit tests/unit/helpers/formDataToStream.test.js: before the fix 1 failure,expected '�\^@' to be an instance of File; after the fix 7/7 pass.npx vitest run --project unit tests/unit/adapters/http.test.js -t FormData: 10 passed.npx eslintandnpx prettier --checkon the changed files: clean.npm run lint: clean.npm run build: succeeded.npm run test:vitest:unit: 1698 passed, 3 failed. The same 3 fail on the base commit without this change, because they need DNS or an outside host and the container has no network:regression > 4999 > should not fail with query parsing,fetch > should not use inherited Symbol.iterator for request headers,fetch > should handle fetch failed error as an AxiosError with ERR_NETWORK code. I am leaving this as a draft until CI runs them.npm run test:vitest:browser:headless: not run.formDataToStreamis only imported bylib/adapters/http.js, which browser builds do not ship.Compatibility and documentation
Patch. Only the Node http adapter (and HTTP/2 through it) changes, for file entries whose name is an empty string, which now carry
filename="", and for blob-like values with a non-stringname, which no longer get afilename. No public API or type change, so noindex.d.ts/index.d.ctsorPRE_RELEASE_DOCS.mdupdate.Checklist
PRE_RELEASE_CHANGELOG.mdentry added or updated (or AGENTS.md's automated release-preparation exception explained)AI assisted with this change and description; I cannot apply labels on this repository, so a maintainer needs to apply
ai-assisted.Found by a defect-hunting pipeline I build and run (Dev-next-gen), using Claude Code with Anthropic's Claude Opus 5.5.
Summary by cubic
Description
Fixes the Node http adapter so native
FormDatafile entries with an empty name are sent withfilename=""in the multipart part header. Previously, the filename parameter was omitted when the name was falsy, so multipart parsers read the upload as a text field and binary content got decoded as UTF-8, corrupting the payload.formDataToStreamhelper to check whethervalue.nameis a string (viautils.isString) rather than truthy before writing thefilenameparameter.filename=""for these entries.value.nameno longer produces afilenameparameter; values without a string name keep the rest of their old output. No public API or type changes.Docs
No documentation update is needed; this only affects internal multipart serialization for empty-named file entries.
Testing
Adds an integration test that posts a native
FormDatawith a file blob that has an empty name through the http adapter to a local server (using the shared test server), parses the received body withResponse.formData(), and verifies the upload arrives as aFilewith the empty name and intact binary content. Existing unit tests for the http adapter FormData path pass.Semantic version impact
Patch. Only the Node http adapter behavior changes for file entries whose name is an empty string or a non-string value; no public API, type, or option changes, so this does not warrant a breaking or minor version bump.
Written for commit 5c48ef5. Summary will update on new commits.