Skip to content

Keep a leading U+FEFF when decoding binary strings - #1572

Merged
timostamm merged 5 commits into
bufbuild:mainfrom
devtechedge:fix/1567-string-bom
Nov 2, 2026
Merged

timostamm merged 5 commits into
bufbuild:mainfrom
devtechedge:fix/1567-string-bom

Conversation

@devtechedge

@devtechedge devtechedge commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1567: A leading U+FEFF in a protobuf string is part of the value, not a byte-order mark. protobuf-es created its TextDecoder without ignoreBOM, so fromBinary silently removed one leading U+FEFF from every string it reads.

This PR passes ignoreBOM: true to both the lenient and the strict decoder in getTextEncoding(). As a result, strings decoded by protobuf-es now keep a leading U+FEFF.

If you depended on the old behavior, strip the character yourself after decoding, for example value.replace(/^\uFEFF/, "").

getTextEncoding() built its UTF-8 decoders without ignoreBOM. The WHATWG
decoder strips a leading U+FEFF, so fromBinary dropped that code point from
string fields. Both decoders now set ignoreBOM, and the strict decoder still
uses fatal.

Adds a decodeUtf8 case and a StringValue round trip.
@CLAassistant

CLAassistant commented Oct 18, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@timostamm
timostamm requested a review from ajeetdsouza October 20, 2026 09:43

@timostamm timostamm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR. I've pushed up corresponding docs changes and additional tests, and updated the PR description to call out the behavioral change. LGTM!

@timostamm
timostamm merged commit 9ef472d into bufbuild:main Nov 2, 2026
28 checks passed
@devtechedge

This comment was marked as low quality.

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.

fromBinary drops a leading U+FEFF from string fields

3 participants