[7392] [cpp] Fix IgnoreUnknownEnumStringValueInMap conformance tests
Motivation
This PR fixes failing JSON conformance tests for cpp with name IgnoreUnknownEnumStringValueInMap. Specifically, for the following input of type TestMapOfEnums:
{
"enum_map": {
"key1": "PROTOCOL",
"key2": "UNKNOWN_ENUM_STRING_VALUE",
"key3": "BUFFER"
}
}
The JSON parser with ignore_unknown_fields=true should produce a map with 2 entries, skipping the unknown enum value under key2. The implementation before this PR outputs key2 with 0-th enum value (PROTOCOL) instead.
The JSON parsing spec was discussed in https://github.com/protocolbuffers/protobuf/issues/7392.
Recent similar changes in other languages:
- Python: https://github.com/protocolbuffers/protobuf/commit/86abf35ef5ee5b1004ec11bebb36d84c2ef6645e
- Swift: https://github.com/apple/swift-protobuf/pull/1345
- C#: https://github.com/protocolbuffers/protobuf/pull/15758
Changes
The main difficulty in implementing the fix is the fact that parser will first allocate a new map entry message and then consume the value. In this special case (unknown enum string value), we need to do it the other way around: first consume the value, then allocate the map entry if needed.
The PR initially contains 5 commits, with first 4 being noop unit tests and refactors:
- unit test that documents the mainline behavior (this test will be changed in the 5th commit)
- noop refactoring that simplifies the signature of ParseEnumFromStr
- noop refactoring that extract map key parsing into a separate function (we'll call it twice in 5th commit)
- noop refactoring that extracts parse map entry into a separate function (since it will get more logic)
- the commit that actually implements the fix and adjusts tests
@haberman friendly ping to take a look :)
@sbenzaquen can you help me ping @haberman through internal channels :) I bet this is a GitHub notifications recall miss.
I am reaching out to you since you recently reviewed https://github.com/protocolbuffers/protobuf/pull/16567
@jskeet, since you worked with me on the linked issue https://github.com/protocolbuffers/protobuf/issues/7392, can you help me get reviewer's attention here through internal channels? I suspect that they are not seeing GitHub notifications.
I am not blocked on this, just wanted to eventually remove the failing tests that I added.
I've pinged internally.
@esrauchg Can you take a look at this?
Sorry @antongrbin for the delays in getting someone to look at this! I can help review/push this forward here from the protobuf team.
[Edit: removed questions that I realized weren't relevant after looking closer]
@esrauchg thank you for your time for the review and apologies for the delay in answering.
As discussed over internal chat, I will close this PR and create an internal change with the comments here addressed.