Skip to content

fix(http): keep empty file names in multipart FormData parts - #11332

Open
Dev-next-gen wants to merge 3 commits into
axios:v1.xfrom
Dev-next-gen:fix/form-data-stream-empty-filename
Open

Dev-next-gen wants to merge 3 commits into
axios:v1.xfrom
Dev-next-gen:fix/form-data-stream-empty-filename

Conversation

@Dev-next-gen

@Dev-next-gen Dev-next-gen commented Oct 17, 2026 •

Copy link
Copy Markdown

Summary

With the Node http adapter, a native FormData file appended with an empty name (form.append('upload', blob, '')) is written without a filename parameter, because formDataToStream only adds it when value.name is truthy. The part still gets a Content-Type, but multipart parsers read a part without filename as a text field: the server receives a string, and binary content is decoded as UTF-8 (ff 00 arrives as '�\^@'). The fetch path's own serializer, formDataToBlob, already writes filename="" for this entry, and formBodyLengthCases expects the parsed upload to come back as a file named ''.

The fix writes filename whenever the entry's name is a string, so an empty name gives filename="". Blob-like values without a name property keep the old output; a blob-like value with a non-string name (e.g. 123) no longer gets a filename parameter.

Linked issue

Fixes #11331

Changes

  • lib/helpers/formDataToStream.js: check utils.isString(value.name) instead of truthiness before writing filename.
  • tests/unit/helpers/formDataToStream.test.js: posts a native FormData with an empty-named file through axios.post and the http adapter to a local server, then parses the received body with Response.formData().
  • PRE_RELEASE_CHANGELOG.md: Bug Fixes entry.

Validation

All commands ran in a node:22-bookworm container (Node 22) after npm 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 eslint and npx prettier --check on 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. formDataToStream is only imported by lib/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-string name, which no longer get a filename. No public API or type change, so no index.d.ts/index.d.cts or PRE_RELEASE_DOCS.md update.

Checklist

  • Scope, target branch, and linked issue/rationale checked
  • PRE_RELEASE_CHANGELOG.md entry added or updated (or AGENTS.md's automated release-preparation exception explained)
  • Regression tests and relevant negative/platform cases covered (or N/A with reason)
  • Applicable local checks completed, with actual commands and results recorded above
  • Deferred release docs and ESM/CJS types/tests updated where needed (or N/A with reason)
  • Semver impact stated and intentional breaking changes explained
  • Final diff reviewed for security, unrelated changes, generated artifacts, and test/debug leftovers
  • Latest GitHub Actions status recorded separately from review/security bot results

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 FormData file entries with an empty name are sent with filename="" 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.

  • Changes the formDataToStream helper to check whether value.name is a string (via utils.isString) rather than truthy before writing the filename parameter.
  • The http adapter now matches the existing behavior of the fetch adapter's serializer, which already wrote filename="" for these entries.
  • A truthy non-string value.name no longer produces a filename parameter; 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 FormData with 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 with Response.formData(), and verifies the upload arrives as a File with 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.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 3 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread PRE_RELEASE_CHANGELOG.md Resolved
@greptile-apps

greptile-apps Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] No outstanding findings block merging. The test now uses the shared HTTP server helpers and performs cleanup in finally.

Summary

Fixes empty file names in multipart uploads through the Node HTTP adapter.

  • The Node HTTP adapter sends empty-name files with filename="".

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

@jasonsaayman jasonsaayman added ai-assisted This PR was created with or in conjunction with AI commit::fix The PR is related to a bugfix v1x Version 1 labels Oct 21, 2026
@jasonsaayman
jasonsaayman marked this pull request as ready for review October 21, 2026 14:01
@jasonsaayman
jasonsaayman self-requested a review as a code owner October 21, 2026 14:01

@jasonsaayman jasonsaayman left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted This PR was created with or in conjunction with AI commit::fix The PR is related to a bugfix v1x Version 1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Node http adapter drops the filename of FormData files with an empty name, so they arrive as text fields

2 participants