Copybara import of the project:

--
064b263c42 by Anton Grbin <anton@noom.com>:

squash and rebase

COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/9534 from noom:anton/MIN-2347/json_conformance_unknown_fields 064b263c42
PiperOrigin-RevId: 488667851
pull/10991/head
Anton Grbin 2 years ago committed by Copybara-Service
parent 47862bbfe2
commit 09f4901084
  1. 36
      conformance/binary_json_conformance_suite.cc
  2. 1
      conformance/binary_json_conformance_suite.h
  3. 2
      conformance/failure_list_cpp.txt
  4. 2
      conformance/failure_list_php.txt
  5. 2
      conformance/failure_list_php_c.txt
  6. 3
      conformance/failure_list_python.txt
  7. 3
      conformance/failure_list_python_cpp.txt
  8. 2
      conformance/failure_list_ruby.txt

@ -1766,6 +1766,7 @@ void BinaryAndJsonConformanceSuite::RunJsonTests() {
RunJsonTestsForStruct();
RunJsonTestsForValue();
RunJsonTestsForAny();
RunJsonTestsForUnknownEnumStringValues();
RunValidJsonIgnoreUnknownTest("IgnoreUnknownJsonNumber", REQUIRED,
R"({
@ -1801,6 +1802,41 @@ void BinaryAndJsonConformanceSuite::RunJsonTests() {
ExpectParseFailureForJson("RejectTopLevelNull", REQUIRED, "null");
}
void BinaryAndJsonConformanceSuite::RunJsonTestsForUnknownEnumStringValues() {
// Tests the handling of unknown enum values when encoded as string labels.
// The expected behavior depends on whether unknown fields are ignored:
// * when ignored, the parser should ignore the unknown enum string value.
// * when not ignored, the parser should fail.
struct TestCase {
// Used in the test name.
string enum_location;
// JSON input which will contain the unknown field.
string input_json;
};
const std::vector<TestCase> test_cases = {
{"InOptionalField", R"json({
"optional_nested_enum": "UNKNOWN_ENUM_VALUE"
})json"},
{"InRepeatedField", R"json({
"repeated_nested_enum": ["UNKNOWN_ENUM_VALUE"]
})json"},
{"InMapValue", R"json({
"map_string_nested_enum": {"key": "UNKNOWN_ENUM_VALUE"}
})json"},
};
for (const TestCase& test_case : test_cases) {
// Unknown enum string value is a parse failure when not ignoring unknown
// fields.
ExpectParseFailureForJson(
absl::StrCat("RejectUnknownEnumStringValue", test_case.enum_location),
RECOMMENDED, test_case.input_json);
// Unknown enum string value is ignored when ignoring unknown fields.
RunValidJsonIgnoreUnknownTest(
absl::StrCat("IgnoreUnknownEnumStringValue", test_case.enum_location),
RECOMMENDED, test_case.input_json, "");
}
}
void BinaryAndJsonConformanceSuite::RunJsonTestsForFieldNameConvention() {
RunValidJsonTest(
"FieldNameInSnakeCase", REQUIRED,

@ -56,6 +56,7 @@ class BinaryAndJsonConformanceSuite : public ConformanceTestSuite {
void RunJsonTestsForStruct();
void RunJsonTestsForValue();
void RunJsonTestsForAny();
void RunJsonTestsForUnknownEnumStringValues();
void RunValidJsonTest(const std::string& test_name, ConformanceLevel level,
const std::string& input_json,
const std::string& equivalent_text_format);

@ -17,6 +17,8 @@ Recommended.Proto3.JsonInput.FieldNameDuplicate
Recommended.Proto3.JsonInput.FieldNameDuplicateDifferentCasing1
Recommended.Proto3.JsonInput.FieldNameDuplicateDifferentCasing2
Recommended.Proto3.JsonInput.FieldNameNotQuoted
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput
Recommended.Proto3.JsonInput.MapFieldValueIsNull
Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull
Recommended.Proto3.JsonInput.RepeatedFieldPrimitiveElementIsNull

@ -5,6 +5,8 @@ Recommended.Proto2.JsonInput.FieldNameExtension.Validator
Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput
Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput
Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataOneofBinary.MESSAGE.Merge.ProtobufOutput
Required.Proto2.JsonInput.StoresDefaultPrimitive.Validator
Required.Proto3.JsonInput.DoubleFieldTooSmall

@ -1,2 +1,4 @@
Recommended.Proto2.JsonInput.FieldNameExtension.Validator
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput
Required.Proto2.JsonInput.StoresDefaultPrimitive.Validator

@ -0,0 +1,3 @@
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInOptionalField.ProtobufOutput
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput

@ -6,3 +6,6 @@
#
# TODO(haberman): insert links to corresponding bugs tracking the issue.
# Should we use GitHub issues or the Google-internal bug tracker?
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInOptionalField.ProtobufOutput
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput

@ -27,6 +27,8 @@ Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.PackedInput.PackedOutp
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT32.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.PackedInput.PackedOutput.ProtobufOutput
Recommended.Proto2.ProtobufInput.ValidDataRepeated.UINT64.UnpackedInput.PackedOutput.ProtobufOutput
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInMapValue.ProtobufOutput
Recommended.Proto3.JsonInput.IgnoreUnknownEnumStringValueInRepeatedField.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataOneofBinary.MESSAGE.Merge.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.BOOL.PackedInput.UnpackedOutput.ProtobufOutput
Recommended.Proto3.ProtobufInput.ValidDataRepeated.BOOL.UnpackedInput.UnpackedOutput.ProtobufOutput

Loading…
Cancel
Save