Skip to content

Fix closed enum parsing#1170

Merged
timostamm merged 1 commit intomainfrom
tstamm/Fix-closed-enum-parsing
Jul 17, 2025
Merged

Fix closed enum parsing#1170
timostamm merged 1 commit intomainfrom
tstamm/Fix-closed-enum-parsing

Conversation

@timostamm
Copy link
Member

Protobuf enums are open in proto3, and closed in proto2. An open enum field can contain values not defined in the enum (for example from a future schema change). A closed enum field can only contain values defined in the enum.

The way we handle closed enums when parsing with fromBinary is flawed. While we never set an enum field to a value not defined in the enum, we do raise a parse error. The correct behavior is to put the unknown value into the set of unknown fields instead. This PR fixes the behavior.

@timostamm timostamm requested a review from srikrsna-buf July 16, 2025 17:23
@timostamm timostamm merged commit 02e1763 into main Jul 17, 2025
22 checks passed
@timostamm timostamm deleted the tstamm/Fix-closed-enum-parsing branch July 17, 2025 08:54
@timostamm timostamm mentioned this pull request Jul 17, 2025
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.

3 participants