Reject externally tagged variants with more than one field - #720
Open
ciprianf-flexion wants to merge 1 commit into
Open
Reject externally tagged variants with more than one field#720ciprianf-flexion wants to merge 1 commit into
ciprianf-flexion wants to merge 1 commit into
Conversation
Reading an rfl::Variant<rfl::Field<...>, ...> from an object with several keys silently kept the last recognized tag, and an unknown key followed by a valid tag overwrote the error. Serde, which this format models, rejects such objects. The reader now returns an error whenever a second field is encountered, mirroring the existing 'found none' error.
ciprianf-flexion
marked this pull request as ready for review
August 28, 2026 09:55
Author
|
@liuzicheng1987 I cannot add you explicitly as a reviewer, but would you mind taking a look? Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reading an
rfl::Variant<rfl::Field<...>, ...>from an object with several keys silently keeps the last recognized tag. Worse, an unknown key followed by a valid tag overwrites the "could not match field" error, so{"triangle": {...}, "circle": {...}}parses successfully as a circle.Serde, which this format models (per variants_and_tagged_unions.md), represents an externally tagged enum as a single-key map and rejects anything else, see serde.rs/enum-representations.html.
This change makes the reader return an error whenever a second field is encountered, mirroring the existing "expected the object to have exactly one field, but found none" error.
Added tests for both cases in
tests/json/test_field_variant_multiple_fields.cpp.