Repository navigation
fix(http): keep filename parameter for files with an empty name - #11355
princejain756 wants to merge 5 commits into
Conversation
jasonsaayman
left a comment
There was a problem hiding this comment.
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 andnew 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
| 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')}"` |
There was a problem hiding this comment.
[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.
There was a problem hiding this comment.
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.
[Low impact] The PR appears safe to merge. SummaryPreserves empty filenames in Node HTTP form uploads so binary content stays a file rather than becoming text.
No new actionable issues found. Tests were not run. Reviews (8) · Last reviewed commit: "test(http): assert uploaded bytes in the..." · Reviewed by Greptile |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
1 issue found across 3 files (changes from recent commits).
Confidence score: 3/5
lib/helpers/formDataToStream.jsno longer usesfilename="blob"for non-string values without a stringname, 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)}"` : '' |
There was a problem hiding this comment.
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>
| !isStringValue && (value.name || value.name === '') ? `; filename="${escapeName(value.name)}"` : '' | |
| !isStringValue | |
| ? `; filename="${escapeName(utils.isString(value.name) ? value.name : 'blob')}"` | |
| : '' |
There was a problem hiding this comment.
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.
|
The unnamed-part fallback is gone as of 25e1121: only a present name (including the empty string) emits 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. |
be7c25a to
4beb9b6
Compare
|
The current diff does not match this finding. Checking !isStringValue && (value.name || value.name === '') ? `; filename="${escapeName(value.name)}"` : ''That guard emits a filename only when
So this PR does not add The earlier No code change is needed for this one unless you can show a case where |
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.
4beb9b6 to
1c77705
Compare
|
Closing in favour of #11332 |
A
FormDatafile appended with an empty name (form.append('upload', blob, '')) was sent without afilenameparameter on the http adapter, becauseformDataToStreamonly emittedfilenamewhenvalue.namewas truthy. Multipart parsers treat a part withoutfilenameas a text field, so the upload arrived as a UTF-8-decoded string and binary bytes were lost.The part now carries
filename="", matching whatformDataToBlob(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
FormDatafiles appended with an empty name (form.append('upload', blob, '')) being serialized without afilenameparameter byformDataToStream. 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.filename=""for empty string names, matching whatformDataToBlobalready writes on the fetch path.filename, exactly as before the fix.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:originalFilename: '') and its bytes are verified round-trip intact rather than arriving as a text field.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.