Repository navigation
descriptor: ignore unknown enum names when a JSON parse ignores unknown fields - #846
Closed
hamza-paracha wants to merge 1 commit into
Closed
hamza-paracha wants to merge 1 commit into
hamza-paracha wants to merge 1 commit into
Conversation
…wn fields DynamicMessage::from_json_ignoring_unknown discarded unknown field names but still failed on an enum name the enum does not declare. Generated code with JsonParseOptions::ignore_unknown_enum_values and protobuf C++ with ignore_unknown_fields both accept it, and the reflection conformance run fails the ten Recommended IgnoreUnknownEnumStringValue* tests. With the flag set, an unknown name now leaves a singular field unset and drops the element of a repeated field or the entry of a map. A null element and an unknown closed-enum number are still errors. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I have read the CLA Document and I hereby sign the CLA 1 out of 2 committers have signed the CLA. |
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.
Summary
DynamicMessage::from_json_ignoring_unknown(DynamicMessageSeed::ignore_unknown_fields(true)) discards unknown field names, but an enum name the enum does not declare was still a parse error:Generated code with
JsonParseOptions::ignore_unknown_enum_valuesaccepts this, and so does protobuf C++, whoseignore_unknown_fieldsalso covers unknown enum names. The conformance runner's reflection mode (BUFFA_VIA_REFLECT=1) parsesJSON_IGNORE_UNKNOWN_PARSING_TESTrequests through this function and fails the tenRecommended.{Proto2,Proto3}.JsonInput.IgnoreUnknownEnumStringValue{InOptionalField,InRepeatedField,InMapValue,InRepeatedPart,InMapPart}tests. CI does not catch it becauserun-conformance.shdoes not pass--enforce_recommended.With the flag set, an unknown name is now ignored the same way the generated path ignores it:
deserialize_enumnow returns a three-stateEnumJson { Value, Null, Unknown }instead ofOption<Value>, so the list and map visitors can tell an ignored element apart fromnull. Anullelement or map value is still an error. Strict parsing is unchanged, and an unknown number for a closed enum is still an error in both modes. Theignore_unknown_fieldsrustdoc and thebuffa::jsonmodule doc that said an unknown enum name is always a parse error forDynamicMessageare updated.Testing
buffa-descriptor/tests/json_e2e.rs:json_lenient_mode_ignores_unknown_enum_namescovers the singular and repeated cases and anullelement. It fails onmainand passes here.cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warningsandcargo test --workspacepass.--enforce_recommended,BUFFA_VIA_REFLECT=1):mainhas 2783 successes and 10 failures (the tests above). This branch has 2793 successes and 0 failures.