Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion conformance/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ cc_library(
"//editions:test_messages_proto2_editions_cc_proto",
"//editions:test_messages_proto3_editions_cc_proto",
"//src/google/protobuf",
"//src/google/protobuf:endian",
"//src/google/protobuf:protobuf_lite",
"//src/google/protobuf/json",
"//src/google/protobuf/util:type_resolver",
Expand Down
110 changes: 110 additions & 0 deletions conformance/binary_json_conformance_suite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3471,6 +3471,68 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::RunJsonTestsForStruct() {
}
}
)");

std::string deep_json = R"({"optionalStruct": {)";
std::string deep_proto = "optional_struct: {\n";
int depth = 25;
for (int i = 0; i < depth; ++i) {
deep_json += R"("n": {)";
deep_proto += R"( fields: {
key: "n"
value: {
struct_value: {
)";
}
deep_json += R"("value": 1)";
deep_proto += R"( fields: {
key: "value"
value: {
number_value: 1
}
}
)";

for (int i = 0; i < depth; ++i) {
deep_json += '}';
deep_proto += R"( }
}
}
)";
}
deep_json += "}}";
deep_proto += "}\n";

RunValidJsonTest("StructDeepNesting25", REQUIRED, deep_json, deep_proto);

{
std::string deep_json = R"({"optionalStruct": {)";
int depth = 90;
for (int i = 0; i < depth; ++i) {
deep_json += R"("n": {)";
}
deep_json += R"("value": 1)";
for (int i = 0; i < depth; ++i) {
deep_json += '}';
}
deep_json += "}}";

ExpectParseFailureForJson("StructDeepNesting90", REQUIRED, deep_json);
}

{
std::string deep_json = R"({"optionalStruct": {)";
int depth = 200;
for (int i = 0; i < depth; ++i) {
deep_json += R"("n": {)";
}
deep_json += R"("value": 1)";
for (int i = 0; i < depth; ++i) {
deep_json += '}';
}
deep_json += "}}";

ExpectParseFailureForJson("StructDeepNesting200", REQUIRED, deep_json);
}
}

template <typename MessageType>
Expand Down Expand Up @@ -3561,6 +3623,54 @@ void BinaryAndJsonConformanceSuiteImpl<MessageType>::RunJsonTestsForValue() {
"optional_value: { number_value: nan}");
ExpectSerializeFailureForJson("ValueRejectInfNumberValue", RECOMMENDED,
"optional_value: { number_value: inf}");

{
std::string deep_json = R"({"optionalValue": )";
std::string deep_proto = "optional_value: {\n";
int depth = 25;
for (int i = 0; i < depth; ++i) {
deep_json += '[';
deep_proto += " list_value: {\n values: {\n";
}
deep_json += '1';
deep_proto += " number_value: 1\n";
for (int i = 0; i < depth; ++i) {
deep_json += ']';
deep_proto += " }\n }\n";
}
deep_json += '}';
deep_proto += "}\n";

RunValidJsonTest("ValueDeepNesting", REQUIRED, deep_json, deep_proto);
}
{
std::string deep_json = R"({"optionalValue": )";
int depth = 90;
for (int i = 0; i < depth; ++i) {
deep_json += '[';
}
deep_json += '1';
for (int i = 0; i < depth; ++i) {
deep_json += ']';
}
deep_json += '}';

ExpectParseFailureForJson("ValueDeepNesting90", REQUIRED, deep_json);
}
{
std::string deep_json = R"({"optionalValue": )";
int depth = 200;
for (int i = 0; i < depth; ++i) {
deep_json += '[';
}
deep_json += '1';
for (int i = 0; i < depth; ++i) {
deep_json += ']';
}
deep_json += '}';

ExpectParseFailureForJson("ValueDeepNesting200", REQUIRED, deep_json);
}
}

template <typename MessageType>
Expand Down
1 change: 1 addition & 0 deletions conformance/failure_list_cpp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Recommended.*.FieldMaskTooManyUnderscore.JsonOutput
Recommended.*.JsonInput.FieldMaskInvalidCharacter # Should have failed to parse, but didn't.
Required.*.JsonInput.SingleValueForRepeatedFieldInt32 # Should have failed to parse, but didn't.
Required.*.JsonInput.SingleValueForRepeatedFieldMessage # Should have failed to parse, but didn't.
Required.*.JsonInput.StructDeepNesting90 # Should have failed to parse, but didn't.
Required.*.ProtobufInput.BadTag_FieldNumberSlightlyTooHigh # Should have failed to parse, but didn't.
# TODO: Uncomment once conformance tests can express failures that are not expected to be fixed.
# Recommended.Editions_Proto2.ProtobufInput.RejectInvalidUtf8.String.MapKey # Should have failed to parse, but didn't.
Expand Down
2 changes: 2 additions & 0 deletions conformance/failure_list_java.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Required.*.JsonInput.Int32FieldPlusSign
Required.*.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotBool # Should have failed to parse, but didn't.
Required.*.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt # Should have failed to parse, but didn't.
Required.*.JsonInput.StringFieldNotAString # Should have failed to parse, but didn't.
Required.*.JsonInput.StructDeepNesting90 # Should have failed to parse, but didn't.
Required.*.JsonInput.ValueDeepNesting90 # Should have failed to parse, but didn't.
Required.*.ProtobufInput.UnknownOrdering.ProtobufOutput # Unknown field mismatch
Required.*.ProtobufInput.BadTag_FieldNumberTooHigh # Should have failed to parse, but didn't.
Required.*.ProtobufInput.BadTag_FieldNumberSlightlyTooHigh # Should have failed to parse, but didn't.
Expand Down
5 changes: 3 additions & 2 deletions conformance/failure_list_python.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing1 # Should have failed to parse, but didn't.
Recommended.*.JsonInput.FieldNameDuplicateDifferentCasing2 # Should have failed to parse, but didn't.
Required.*.JsonInput.StructDeepNesting25.ProtobufOutput # Failed to parse input or produce output.
Required.*.ProtobufInput.BadTag_FieldNumberTooHigh # Should have failed to parse, but didn't.
Required.*.ProtobufInput.BadTag_FieldNumberSlightlyTooHigh # Should have failed to parse, but didn't.
Required.*.ProtobufInput.BadTag_OverlongVarint # Should have failed to parse, but didn't.
Expand Down
Loading