Add three conformance test edge cases for ProtoJSON repr of Any

1) An Any with no type_url or value should be represented as `{}`
2) A `null` should be handled as the Any being absent.
3) JSON of `{"@type_url": "", "value":""}` should be a parse failure.

PiperOrigin-RevId: 712938072
pull/19882/head
Protobuf Team Bot 2 months ago committed by Copybara-Service
parent 79e331f4b8
commit b985164e7c
  1. 34
      conformance/binary_json_conformance_suite.cc
  2. 4
      conformance/failure_list_csharp.txt
  3. 1
      conformance/failure_list_jruby.txt
  4. 1
      conformance/failure_list_jruby_ffi.txt
  5. 1
      conformance/failure_list_php.txt
  6. 1
      conformance/failure_list_php_c.txt
  7. 1
      conformance/failure_list_ruby.txt
  8. 1
      upb/conformance/conformance_upb_failures.txt

@ -3524,6 +3524,40 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::RunJsonTestsForAny() {
}
}
)");
// When the Any is in WKT form (with "@type"), the type_url must be present
// and URL shaped, otherwise it should be a parse error (because it can't be
// parsed into the Any schema).
ExpectParseFailureForJson("AnyWktRepresentationWithEmptyTypeAndValue",
REQUIRED,
R"({
"optionalAny": {
"@type": "",
"value": ""
}
})");
ExpectParseFailureForJson("AnyWktRepresentationWithBadType", REQUIRED,
R"({
"optionalAny": {
"@type": "not_a_url",
"value": ""
}
})");
// When the Any can be parsed as non-WKT form, the type_url could be missing
// or invalid, since that can still be parsed into the Any schema.
RunValidJsonTest("AnyWithNoType", REQUIRED,
R"({
"optionalAny": {}
})",
R"(
optional_any: {}
)");
// `null` where an Any exists should just result in the field being unset.
RunValidJsonTest("AnyNull", REQUIRED,
R"({
"optionalAny": null
})",
R"(
)");
}
template <typename MessageType>

@ -33,3 +33,7 @@ Recommended.Editions_Proto3.ValueRejectInfNumberValue.JsonOutput
Recommended.Editions_Proto3.ValueRejectNanNumberValue.JsonOutput
Required.Editions_Proto2.ProtobufInput.UnknownOrdering.ProtobufOutput
Required.Editions_Proto3.ProtobufInput.UnknownOrdering.ProtobufOutput
Required.*.JsonInput.AnyWithNoType.* # Failed to parse input or produce output.
Required.*.JsonInput.AnyWktRepresentationWithEmptyTypeAndValue # Should have failed to parse, but didn't.
Required.*.JsonInput.AnyWktRepresentationWithBadType # Should have failed to parse, but didn't.

@ -144,3 +144,4 @@ Required.Editions_Proto2.ProtobufInput.UnknownOrdering.ProtobufOutput
Required.Editions_Proto3.ProtobufInput.UnknownOrdering.ProtobufOutput
Required.Proto2.ProtobufInput.UnknownOrdering.ProtobufOutput
Required.Proto3.ProtobufInput.UnknownOrdering.ProtobufOutput
Required.*.JsonInput.AnyWithNoType.JsonOutput # Failed to parse input or produce output.

@ -1 +1,2 @@
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.
Required.*.JsonInput.AnyWithNoType.* # Failed to parse input or produce output.

@ -31,3 +31,4 @@ Required.*.ProtobufInput.ValidDataRepeated.FLOAT.PackedInput.JsonOutput
Required.*.ProtobufInput.ValidDataRepeated.FLOAT.UnpackedInput.JsonOutput
Required.*.ProtobufInput.ValidDataScalar.FLOAT[2].JsonOutput
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.
Required.*.JsonInput.AnyWithNoType.*

@ -7,3 +7,4 @@ Required.Proto2.JsonInput.EnumField.ProtobufOutput
Required.Proto2.JsonInput.EnumFieldNumericValueZero.JsonOutput
Required.Proto2.JsonInput.EnumFieldNumericValueZero.ProtobufOutput
Required.Proto2.JsonInput.StoresDefaultPrimitive.Validator
Required.*.JsonInput.AnyWithNoType.*

@ -1 +1,2 @@
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.
Required.*.JsonInput.AnyWithNoType.*

@ -1 +1,2 @@
Required.*.JsonInput.Int32FieldQuotedExponentialValue.* # Failed to parse input or produce output.
Required.*.JsonInput.AnyWithNoType.* # Failed to parse input or produce output.
Loading…
Cancel
Save