Skip to content

fix: discard the initial UTF-8 BOM when decoding text - #201

Open
mayankdhingra02 wants to merge 1 commit into
npm:mainfrom
mayankdhingra02:codex/decode-leading-utf8-bom
Open

mayankdhingra02 wants to merge 1 commit into
npm:mainfrom
mayankdhingra02:codex/decode-leading-utf8-bom

Conversation

@mayankdhingra02

Copy link
Copy Markdown

A leading UTF-8 BOM currently survives text() and makes json() reject otherwise valid JSON. The same decoding issue affects the Blob.text() returned by a response.

Discard exactly one initial BOM when decoding UTF-8 text. Interior BOMs, a second leading BOM and incomplete byte sequences keep their existing meaning. Raw buffer(), arrayBuffer(), Blob bytes and sizes are preserved; the optional charset-conversion path is unchanged.

Validation on macOS:

  • All ten test files pass with 100% coverage on Node 22.22.2, 22.23.5, 24.15.0, 24.22.2, 26.0.0 and 26.13.0.
  • Full npm test, including ESLint and the template check, passes on Node 24.20.0. Pristine main passes that gate too.
  • The new Body/Blob regressions fail on main and pass with the fix, including a BOM split across stream chunks.
  • Native Request/Response/Blob comparisons and a local HTTP fixture verify JSON, text, raw bytes and clone reads. The packed package passes the same checks after an offline install.

Repeated-BOM expectations follow the Encoding Standard's single-BOM rule; Node 24's Response decoding differs for that case. Clone checks consume both branches concurrently; the existing sequential-read backpressure behavior is unchanged from main. Linux and Windows execution remain for CI. Dependencies and generated tooling are unchanged.

@mayankdhingra02
mayankdhingra02 requested a review from a team as a code owner November 24, 2026 17:04
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