Repository navigation
Conversation
Keep empty names distinct from a literal undefined field when converting FormData to JSON, without changing separator-only name handling. Cover native browser round trips and record the required prerelease notes. Co-Authored-By: OpenAI GPT-6 <[email protected]>
|
| * @returns An array of strings. | ||
| */ | ||
| function parsePropPath(name) { | ||
| if (name === '') return ['']; |
There was a problem hiding this comment.
When FormData contains fields named '' and '[]', both now map to the empty-string JSON key. formToJSON() combines their values into one array, so callers cannot tell which value came from which field. This is a non-blocking edge case, but it can lose field identity when converting data.
Artifacts
Executable empty-name and brackets reproduction
- The authored Node script runs the parent or current helper against identical FormData and toFormData inputs, asserting the observed outputs.
Parent-commit helper output with distinct values
- The parent-commit helper was executed on both inputs and placed the values under `undefined` and the empty key, showing that round-tripping was already imperfect but the values did not combine.
Changed helper output with combined values
- The current helper was executed on the same inputs and returned both values in one empty-key array, confirming the collision.
Ran code and verified through T-Rex
Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/helpers/formDataToJSON.js
Line: 26
Comment:
**Distinct field names merge**
When FormData contains fields named `''` and `'[]'`, both now map to the empty-string JSON key. `formToJSON()` combines their values into one array, so callers cannot tell which value came from which field. This is a non-blocking edge case, but it can lose field identity when converting data.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Document and verify that root array notation targets the empty-string JSON key used by the existing serializer, including native browser round trips. Runtime code is unchanged. Co-Authored-By: OpenAI GPT-6 <[email protected]>
There was a problem hiding this comment.
PR #11278 - fix(form-data): preserve truly empty field names
Repo: axios/axios Author: @maple-pwn Base: v1.x Files: 5 **+82/-0
CI: Unavailable: no checks returned; no build/test workflow result is present in this snapshot. Mergeability: conflicting. Reviewed head: 35f1f12c034874ce78715c4ac2b28637aa0133b0.
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 and merge conflicts 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
An actual empty FormData field name produced no parsed path tokens and was treated as the string key undefined, colliding with a real field of that name. This change supplies an empty token only for the actual empty name. Executed form with ["","a"] and ["undefined","b"]: the target returned {"undefined":["a","b"]}; this head returned {"":"a","undefined":"b"}. Separator-only legacy inputs and bracket paths remain separate cases rather than all becoming empty-name fields.
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 formDataToJSON in:title,body, 11295 in:title,body, credential redaction 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.
#11296 and #11328 address the same length-slot failure. #11296 uses a narrower guard and has both insertion orders plus browser HTML-form coverage, so it is preferred. #11278 preserves empty field names; #11280 supplies a benchmark; #11299 strengthens hardening tests. Those are complementary. Newly opened #11353 uses the same targeted guard as #11296, with fewer regressions and no prerelease entry; its combined length/nested/dotted cases are covered by #11296.
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 duplicate closure: the candidates are complementary or no equivalent solution was found.
Project Fit
North star: Reliable HTTP transport and configuration across supported JavaScript environments, without embedding application-specific policy.
Benefits: Preserves genuine empty field names separately from a literal undefined key.
Tradeoffs: Empty keys are valid form data; preserving them is a data fidelity fix, while changing all tokenless syntax would be a broader compatibility decision.
Fit: Strong — The underlying problem belongs in the transport, serializer, declarations or their maintenance tests.
Adversarial Review
Strongest objection: Empty keys are valid form data; preserving them is a data fidelity fix, while changing all tokenless syntax would be a broader compatibility decision. Latest-head integration evidence is still needed.
Abuse/failure modes checked: Reviewed repeated empty names, collisions with literal undefined, bracket syntax, separator-only names and browser round trips. Ran the public formToJSON example.
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. PRE_RELEASE_DOCS.md also captures the relevant deferred documentation.
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. Empty keys are valid form data; preserving them is a data fidelity fix, while changing all tokenless syntax would be a broader compatibility decision.
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.
- GitHub reports merge conflicts with the current target. Resolve them and re-run relevant checks; the reviewed source snapshot is not a tested merge result.
Non-Blocking Suggestions
- Retain the literal undefined collision regression, since a single empty field would not expose the data loss clearly.
Looks Good
- Reviewed repeated empty names, collisions with literal undefined, bracket syntax, separator-only names and browser round trips. Ran the public formToJSON example.
Summary
axios.formToJSON()currently turns an empty FormData field name into the string keyundefined. If a real field is namedundefined, their values are merged. Preserve an actually empty name as the empty-string key instead.Linked issue
Follow-up to the author-closed #11191. That implementation also changed nonempty separator-only names; this version handles only
name === ''and adds explicit regression guards for the previously identified side effect.Changes
undefinedfield, and unchanged conversion of.,[,],[[, and][.toFormData/formToJSONround trip with native browser FormData.[]notation used bytoFormDatafor an array under an empty-name JSON key, with additional unit and browser coverage.Validation
Node 26.10.0 on macOS arm64. Proxy environment variables were unset for the local test servers; browser binaries are installed in a workspace-specific directory.
npm ci --ignore-scripts.npm run lint: pass.npm run build: pass.npm run test:vitest:unit: 69 files, 1,297 tests passed.npm run test:vitest:browser:headless: 69 browser/file combinations, 798 tests passed, 3 skipped.npx --no-install prettier --checkfor all five changed files andgit diff --check: pass.npm run test:vitest:unit -- tests/unit/helpers/formDataToJSON.test.jspasses all 23 tests, andnpm run test:vitest:browser:headless -- tests/browser/formdata.browser.test.jspasses all 9 tests across the three browsers after adding root-array coverage. Formatting and diff checks also pass.35f1f12: Socket's two checks, cubic, and Greptile all passed. Greptile now assigns confidence 5/5 and describes the documented root[]/empty-name alias as non-blocking. No Actions build/test checks are reported yet; these review/security checks do not establish that the CI build and runtime matrix passed.AI assistance: applying the required
ai-assistedlabel withgh pr create --label ai-assistedfailed because this account does not have permission to update repository labels. A maintainer needs to apply that label.Compatibility and documentation
Patch correction for Node and browsers, with no new options, exports, declarations, or dependencies. Nonempty field names retain their existing behavior, including separator-only names. Declaration/module and packed-package suites are not applicable because types, exports, packaging, and build configuration are unchanged. The normal build is verified above.
PRE_RELEASE_DOCS.mdrecords the empty-key example for release preparation; README and docs-site changes are deferred as required.Root
[]already represents an array under the empty-string JSON key:toFormData({ '': ['first', 'second'] }, new FormData())creates two[]fields. The empty raw name and root array notation therefore address the same logical key under the existing path syntax. Their values combine at that key; the added round-trip tests and release documentation make this explicit. Nonempty separator-only names that produce no path segments still retain their prior behavior.Checklist
PRE_RELEASE_CHANGELOG.mdentry added or updated