Skip to content

fix: replace Buffer.from with Uint8Array in toFormData - #11018

Merged
jasonsaayman merged 4 commits into
axios:v1.xfrom
mixelburg:fix/drop-buffer-from-toFormData
Jun 25, 2026
Merged

jasonsaayman merged 4 commits into
axios:v1.xfrom
mixelburg:fix/drop-buffer-from-toFormData

Conversation

@mixelburg

@mixelburg mixelburg commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #10990

The only use of Buffer in client-facing code is a single Buffer.from(value) fallback in toFormData.js. Bundlers like Webpack (used by Next.js) detect this reference and pull in the full buffer polyfill into browser bundles.

Replaced with new Uint8Array(value) which is a native browser API accepted by both FormData and Node.js form-data. Also updated the error message on the Blob guard to reference ArrayBuffer/TypedArray instead of Buffer.

All 596 unit tests pass.


Summary by cubic

Replaced direct Buffer.from in toFormData with a Node-only wrapper and browser-safe Uint8Array/Blob handling to avoid bundler buffer polyfills while keeping Node behavior intact.

Description

  • Summary of changes
  • Reasoning
    • Prevents bundlers from injecting buffer polyfills in web builds while preserving Node conversion for non-spec FormData.
  • Additional context
    • Main logic change is in lib/helpers/toFormData.js.

Docs

  • Update /docs/ to note toFormData accepts ArrayBuffer/TypedArray in all environments; browsers produce Blob, and Node may use Buffer for non-spec FormData. No Buffer requirement in browsers.

Testing

  • Added browser test: TypedArray converts to Blob and round-trips bytes.
  • Added Node unit test: TypedArray converts to Buffer for non-spec FormData.
  • Existing error-path test for missing Buffer still applies. No additional tests needed.

Semantic version impact

  • Patch: internal implementation change only; no API changes.

Written for commit 832c9f8. Summary will update on new commits.

Review in cubic

@mixelburg
mixelburg requested a review from jasonsaayman as a code owner June 16, 2026 22:09

@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 1 file

Confidence score: 5/5

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

Re-trigger cubic

Comment thread lib/helpers/toFormData.js Outdated
@jasonsaayman jasonsaayman added status::changes-requested A reviewer requested changes to the PR commit::fix The PR is related to a bugfix labels Jun 18, 2026

@mixelburg mixelburg left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The changes requested by @jasonsaayman have been addressed in commit d701c4a (added typeof Buffer !== "undefined" guard). Requesting re-review.

…toFormData

# Conflicts:
#	lib/helpers/toFormData.js
…toFormData

# Conflicts:
#	PRE_RELEASE_CHANGELOG.md
@jasonsaayman
jasonsaayman merged commit 3243566 into axios:v1.x Jun 25, 2026
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit::fix The PR is related to a bugfix status::changes-requested A reviewer requested changes to the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove direct usage of Buffer

2 participants