Skip to content

fix(http): keep filename parameter for files with an empty name - #11355

Closed
princejain756 wants to merge 5 commits into
axios:v1.xfrom
princejain756:fix-formdata-empty-filename
Closed

princejain756 wants to merge 5 commits into
axios:v1.xfrom
princejain756:fix-formdata-empty-filename

Conversation

@princejain756

@princejain756 princejain756 commented Oct 21, 2026 •

Copy link
Copy Markdown

A FormData file appended with an empty name (form.append('upload', blob, '')) was sent without a filename parameter on the http adapter, because formDataToStream only emitted filename when value.name was truthy. Multipart parsers treat a part without filename as a text field, so the upload arrived as a UTF-8-decoded string and binary bytes were lost.

The part now carries filename="", matching what formDataToBlob (fetch path) already writes for the same entry, and parts whose value has no string name still serialize without a filename, exactly as before.

Fixes #11331


Summary by cubic

Description

Fixes FormData files appended with an empty name (form.append('upload', blob, '')) being serialized without a filename parameter by formDataToStream. Multipart parsers treated such a part as a text field, so the upload arrived as a UTF-8-decoded string and binary bytes were lost.

Docs

No documentation website changes. Added a changelog entry under Bug Fixes in PRE_RELEASE_CHANGELOG.md.

Testing

Added unit tests in tests/unit/adapters/http.test.js:

  • A file with an empty name is parsed as a file (originalFilename: '') and its bytes are verified round-trip intact rather than arriving as a text field.
  • A non-string part without a name still serializes without a filename.

Semantic version impact

Patch release: bug fix with no API or behavior changes outside the empty-filename case.

Written for commit 1c77705. Summary will update on new commits.

View guided diff

@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 #11355 - fix(http): keep filename parameter for files with an empty name

Repo: axios/axios Author: @princejain756 Base: v1.x Files: 2 **+36/-1
CI: Unavailable: no checks returned; no build/test workflow result is present in this snapshot. Mergeability: mergeable. Reviewed head: b08dc2cb1f6a3e8fd1bde1d1e93120332fa0fc7a.

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

Block — Concrete source/test/API issues below must be resolved before merge.

Change Explanation And User Impact

The HTTP multipart serializer omitted filename when a File name was an empty string, so parsers treated the binary upload as a text field. This head always adds a filename for non-string parts: it preserves an empty string and substitutes "blob" for non-string or absent names. The first part fixes #11331; the fallback is an additional behavior change. Executed using the SpecFormData-style fixture already used by the helper tests and an unnamed Blob containing abc: the target and #11332 produce a text field "abc", while this head produces a File named "blob" of size 3. The committed HTTP regression covers an explicit empty name but not that new fallback. Native FormData normally assigns a filename when wrapping a Blob; custom FormData/helper consumers are the boundary affected by the extra policy.

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, 11331 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.

Compared #11332 and #11355 after refreshed open searches. Both retain filename="". #11332 preserves existing unnamed Blob handling and checks exact binary bytes with native multipart parsing; #11355 adds a blob fallback and uses the existing HTTP multipart receiver. #11351 concerns Fetch native headers and is complementary. Keep the two filename proposals open until the fallback contract and useful receiver coverage are consolidated.

Preferred PR: Prefer the narrow compatibility behavior in #11332 for the empty-name patch; no final duplicate closure until the extra fallback policy and receiver coverage are resolved.

Unique contributions: Preserve the existing multipart-receiver integration from #11355 and the exact binary-byte/native-parser assertions from #11332, with attribution.

Action: Keep both filename proposals open pending an explicit fallback decision and test consolidation.

Project Fit

North star: Reliable HTTP transport and configuration across supported JavaScript environments, without embedding application-specific policy.

Benefits: Preserves empty-named file uploads, but the broader fallback needs a compatibility decision.

Tradeoffs: Matching the Fetch fallback may be a useful design, but it changes how existing unnamed parts are classified by servers and exceeds the narrow empty-string fix.

Fit: Strong — The underlying problem belongs in the transport, serializer, declarations or their maintenance tests.

Adversarial Review

Strongest objection: Preserve or explicitly validate the unnamed-part compatibility change

Abuse/failure modes checked: Read the full diff and issue #11331, compared #11332 and the Fetch serializer, and ran the unnamed-Blob fixture through multipart generation and native parsing. Inspected HTTP test cleanup, ephemeral port, one-shot agent, filename/size assertions and the absence of fallback coverage.

Result: Confirmed issue(s) are listed below and attached inline.

Disposition

Continue
Address the specific blockers below; no unrelated scope or complementary PR should be closed.

Semver

major — As submitted, reclassifies existing unnamed Blob parts from fields to files; narrow the patch or explicitly route that compatibility change.

Breaking Changes

lib/helpers/formDataToStream.js — unnamed non-string values gain filename="blob" and are classified as files instead of fields. Preserve existing behavior for a v1 patch, or agree a major/opt-in migration with regression and release coverage.

Documentation

Add PRE_RELEASE_CHANGELOG.md. If retaining the unnamed/non-string fallback, document that wire-behavior change and its compatibility route in PRE_RELEASE_DOCS.md; do not describe the entire diff as only preserving empty names.

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. Matching the Fetch fallback may be a useful design, but it changes how existing unnamed parts are classified by servers and exceeds the narrow empty-string fix.

Regression risk: medium — demonstrated compatibility/failure case requires correction.

Evidence requested: A fixed reproduction plus the relevant latest-head CI checks.

Blocking Issues

  • lib/helpers/formDataToStream.js:22 — This does more than retain filename="". It also adds filename="blob" to every unnamed non-string part. Executed with the SpecFormData fixture shape already used by the helper tests and new Blob(["abc"]): the target serializes a text field, whereas this head is parsed as a File named blob. #11332 fixes empty string names while preserving that existing unnamed-part behavior. Limit this patch to the empty-name correction, or explicitly decide the compatibility route and add tests/docs for absent and non-string names. The added HTTP test covers only name="" and does not validate the new fallback.
  • PRE_RELEASE_CHANGELOG.md / PRE_RELEASE_DOCS.md — record the fix and any retained fallback compatibility change.
  • 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

  • Strengthen the new receiver regression to assert the actual binary bytes, as #11332 does; filename and size alone cannot establish content preservation.

Looks Good

  • Read the full diff and issue #11331, compared #11332 and the Fetch serializer, and ran the unnamed-Blob fixture through multipart generation and native parsing. Inspected HTTP test cleanup, ephemeral port, one-shot agent, filename/size assertions and the absence of fallback coverage.

Comment thread lib/helpers/formDataToStream.js Outdated
let headers = `Content-Disposition: form-data; name="${escapeName(name)}"${
!isStringValue && value.name ? `; filename="${escapeName(value.name)}"` : ''
!isStringValue
? `; filename="${escapeName(utils.isString(value.name) ? value.name : 'blob')}"`

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.

[P2] Preserve or explicitly validate the unnamed-part compatibility change

This does more than retain filename="". It also adds filename="blob" to every unnamed non-string part. Executed with the SpecFormData fixture shape already used by the helper tests and new Blob(["abc"]): the target serializes a text field, whereas this head is parsed as a File named blob. #11332 fixes empty string names while preserving that existing unnamed-part behavior. Limit this patch to the empty-name correction, or explicitly decide the compatibility route and add tests/docs for absent and non-string names. The added HTTP test covers only name="" and does not validate the new fallback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch. The 'blob' fallback was wider than the reported bug: it also named parts that never carried a filename, so unnamed non-string parts flipped from text fields to file parts.

Narrowed in 25e1121: the guard is now value.name || value.name === '' so absent names and non-string names serialize exactly as before and only the empty-string name survives. Added a wire-level test asserting a nameless Blob part emits no filename= at all, alongside the existing name="" coverage. Changelog updated to describe the preserved behavior.

@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.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

View guided diff | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

Preserves empty filenames in Node HTTP form uploads so binary content stays a file rather than becoming text.

  • Node HTTP uploads keep an explicitly empty filename.

No new actionable issues found. Tests were not run.

Reviews (8) · Last reviewed commit: "test(http): assert uploaded bytes in the..." · Reviewed by Greptile

Comment thread lib/helpers/formDataToStream.js Resolved

@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 1 file (changes from recent commits).

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

View guided diff | Re-trigger cubic

Comment thread PRE_RELEASE_CHANGELOG.md Resolved

@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.

1 issue found across 3 files (changes from recent commits).

Confidence score: 3/5

  • lib/helpers/formDataToStream.js no longer uses filename="blob" for non-string values without a string name, contrary to the PR description. Restore that fallback to avoid changing filenames for those values.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="lib/helpers/formDataToStream.js">

<violation number="1" location="lib/helpers/formDataToStream.js:21">
P2: Custom agent: **Flag AI Slop and Fabricated Changes**

This removes the `filename="blob"` fallback for non-string values without a string `name`, despite the PR description saying `'blob'` remains the fallback. Preserve that fallback while still emitting `filename=""` for an explicit empty name.</violation>
</file>

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

View guided diff | Re-trigger cubic


let headers = `Content-Disposition: form-data; name="${escapeName(name)}"${
!isStringValue && value.name ? `; filename="${escapeName(value.name)}"` : ''
!isStringValue && (value.name || value.name === '') ? `; filename="${escapeName(value.name)}"` : ''

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.

P2: Custom agent: Flag AI Slop and Fabricated Changes

This removes the filename="blob" fallback for non-string values without a string name, despite the PR description saying 'blob' remains the fallback. Preserve that fallback while still emitting filename="" for an explicit empty name.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/helpers/formDataToStream.js, line 21:

<comment>This removes the `filename="blob"` fallback for non-string values without a string `name`, despite the PR description saying `'blob'` remains the fallback. Preserve that fallback while still emitting `filename=""` for an explicit empty name.</comment>

<file context>
@@ -18,9 +18,7 @@ class FormDataPart {
-      !isStringValue
-        ? `; filename="${escapeName(utils.isString(value.name) ? value.name : 'blob')}"`
-        : ''
+      !isStringValue && (value.name || value.name === '') ? `; filename="${escapeName(value.name)}"` : ''
     }${CRLF}`;
 
</file context>
Suggested change
!isStringValue && (value.name || value.name === '') ? `; filename="${escapeName(value.name)}"` : ''
!isStringValue
? `; filename="${escapeName(utils.isString(value.name) ? value.name : 'blob')}"`
: ''

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The description was stale, not the code. Upstream never emitted filename="blob" for a nameless value: the original guard is value.name truthiness, and the spec path only gets 'blob' because the platform coerces the entry to a File named 'blob' before the helper sees it. My first narrowing commit accidentally introduced a fallback that named every nameless part; 25e1121 removed it again so absent and non-string names serialize exactly as before. The description now matches the code (updated in place), and 9102826 extends FormDataSpecCompliant in the new test.

Comment thread tests/unit/adapters/http.test.js Resolved
@princejain756

Copy link
Copy Markdown
Author

The unnamed-part fallback is gone as of 25e1121: only a present name (including the empty string) emits filename now, so parts without a name keep the previous field disposition. The changelog entry sits under Bug Fixes.

At the current head (9971c84) the regression also asserts the uploaded bytes: the empty-name file is read back from the parsed upload and compared byte-for-byte, and a second test pins that a nameless non-string part still arrives without a filename. vitest unit at this head: 1701/1702, the single failure being the pre-existing fetch Symbol.iterator environment failure that also fails on a clean v1.x checkout.

@princejain756
princejain756 force-pushed the fix-formdata-empty-filename branch 3 times, most recently from be7c25a to 4beb9b6 Compare November 4, 2026 05:20
@princejain756

Copy link
Copy Markdown
Author

The current diff does not match this finding. Checking lib/helpers/formDataToStream.js at HEAD:

!isStringValue && (value.name || value.name === '') ? `; filename="${escapeName(value.name)}"` : ''

That guard emits a filename only when value.name is a non-empty string, or when it is exactly the empty string.

So this PR does not add filename="blob" to unnamed non-string parts. It never did at any point in this branch, and the PR description says the opposite of that behaviour, quoting the same guard.

The earlier filename="blob" fallback was in the first revision, was correctly flagged, and was removed in 25e1121. This finding applies that removed revision to the current head. The unit test added here pins the current behaviour: a non-string part without a name still serializes without a filename, and the empty-name file round-trips as a file with originalFilename: '' and its bytes intact.

No code change is needed for this one unless you can show a case where value.name is undefined and a filename parameter still appears at HEAD. If such a case exists I will fix it immediately.

princejain756 and others added 5 commits November 19, 2026 17:07
formDataToStream only emitted filename when value.name was truthy, so
a FormData file appended with an empty name went out as a plain text
part and its bytes were decoded as UTF-8 server-side. The part now
carries filename="" the way the fetch serializer in formDataToBlob
already does, with 'blob' kept as the fallback for non-string names.

Fixes axios#11331
The 'blob' fallback also named parts that never carried a filename,
turning unnamed non-string parts into file parts. Keep the previous
truthiness semantics so absent and non-string names serialize exactly
as before; only the empty-string name now survives.
@princejain756
princejain756 force-pushed the fix-formdata-empty-filename branch from 4beb9b6 to 1c77705 Compare November 19, 2026 11:40
@jasonsaayman

Copy link
Copy Markdown
Member

Closing in favour of #11332

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

Labels

None yet

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