Skip to content

fix(http): strip BOM for UTF-8 response encoding aliases - #11477

Closed
hakarrr wants to merge 3 commits into
axios:v1.xfrom
hakarrr:patch-1
Closed

hakarrr wants to merge 3 commits into
axios:v1.xfrom
hakarrr:patch-1

Conversation

@hakarrr

@hakarrr hakarrr commented Nov 18, 2026 •

Copy link
Copy Markdown

Summary

The HTTP adapter decodes utf8, utf-8 and their case variants with Node's Buffer API, but only strips a leading UTF-8 BOM for the literal utf8 spelling. With strict JSON parsing, the other valid spellings reject the same BOM-prefixed response.

This makes the BOM check match the UTF-8 aliases in both buffered HTTP responses and data URL text responses.

Linked issue

No separate issue. This is a two-condition consistency fix for an existing encoding option, with a localhost reproduction and failing-before/passing-after coverage. It does not add an encoding or change the API.

Changes

  • Match UTF-8 aliases case-insensitively, with or without the hyphen.
  • Add 18 tests covering strict HTTP JSON, data URL text, other encodings, and byte preservation for arraybuffer/stream responses.
  • Add a prerelease bug-fix entry.

Validation

Linux, fresh dependency installation with Node 22, followed by validation with Node 26.13.1:

  • npm ci --ignore-scripts: passed with Node 22; no dependency or lockfile changes.
  • npm run lint: passed.
  • npm run build: passed.
  • npm run test:vitest:unit: 78 files, 1,818 tests passed in one run.
  • npm run test:vitest:browser:headless: Chromium, Firefox and WebKit, 84 files, 1,131 tests passed, 3 skipped.
  • Focused regression suite: 18 passed with the fix; restoring only lib/adapters/http.js to the base gives 8 failures and 10 passes.
  • git diff --check: passed.

WebKit required additional shared libraries in the local environment. They were extracted into a private directory, and an isolated browser wrapper retained that process-local library path. Launch validation remained enabled; no host packages were installed.

The earlier Node 22 unit run failed an unrelated inherited-Symbol.iterator fetch test, which also fails on the untouched base with that runtime. The complete Node 26 run above passes. An earlier isolated HTTP/2 run needed the suite's existing retry; the final complete unit run passed.

GitHub Actions status for this PR still needs checking after submission; local passes are not a hosted-matrix result.

Compatibility and documentation

Patch-level bug fix for Node's HTTP adapter. No public API, type, export, packaging or build configuration changes, and no intentional breaking change. Non-UTF-8 decoding and binary/stream response bytes are unchanged.

No deferred docs change is needed: the existing responseEncoding option already accepts Node Buffer encodings. This corrects inconsistent handling of those encodings rather than introducing a new option. index.d.ts and index.d.cts need no changes. Packed module/smoke suites are not applicable to this source-only adapter fix.

Checklist

  • Scope, target branch, and linked issue/rationale checked
  • PRE_RELEASE_CHANGELOG.md entry added
  • Regression tests and negative/platform cases covered
  • Applicable local checks completed with results above
  • Docs and types considered; no change needed for the reasons above
  • Patch-level semver impact stated; no intentional breaking change
  • Final diff checked for unrelated changes, generated artifacts and debug leftovers
  • Latest GitHub Actions status checked after publication

AI-assisted contribution. I cannot apply repository labels through this submission route; a maintainer needs to add ai-assisted.


Summary by cubic

Description

The Node HTTP adapter now strips a leading UTF-8 BOM for all supported UTF-8 encoding spellings (utf8, utf-8, UTF8, UTF-8) instead of only the literal utf8. Previously, responses decoded with the other aliases kept the BOM, which could break strict JSON parsing and leave a leading \uFEFF in text responses.

Reasoning: the responseEncoding option already accepts Node Buffer encodings, so all UTF-8 aliases should behave consistently. The change covers both buffered HTTP responses and data URL text responses; non-UTF-8 encodings and binary or stream bytes are unchanged.

Additional context: this is a patch-level consistency fix and does not add an encoding or change the public API.

Docs

No documentation change needed. The responseEncoding option already supports Node Buffer encodings; no new option is introduced.

Testing

Added tests/unit/adapters/http-bom-encoding.test.js with 18 cases: strict HTTP JSON parsing and data URL text for the default and five UTF-8 spellings, byte preservation for latin1, hex, base64, and utf16le, and unchanged BOM bytes in arraybuffer and stream responses. The 8 cases exercising the aliases fail without the fix. All existing unit and browser suites, lint, and build pass.

Semantic version impact

Patch-level bug fix. No public API, type, export, packaging, or build configuration changes, and no intentional breaking behavior.

Written for commit cadb794. Summary will update on new commits.

View guided diff

@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues were found.

Summary

The Node HTTP adapter now strips a leading BOM for case variants of utf8 and utf-8, matching its existing default behavior.

  • UTF-8 response text now loses its leading BOM for every alias.

Reviews (4) · Last reviewed commit: "test(http): cover UTF-8 BOM aliases and ..." · Reviewed by Greptile

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

@hakarrr

hakarrr commented Nov 25, 2026

Copy link
Copy Markdown
Author

Friendly follow-up on this PR. If you'd like anything changed or added, let me know and I'll update it.

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.

1 participant