diff --git a/objectivec/Tests/unittest.proto b/objectivec/Tests/unittest.proto index 31353b467b..3c90fd9117 100644 --- a/objectivec/Tests/unittest.proto +++ b/objectivec/Tests/unittest.proto @@ -1098,7 +1098,11 @@ message TestHugeFieldNumbers { bytes oneof_bytes = 536870014; } - extensions 536860000 to 536869999; + extensions 530000000 to 536869999 [declaration = { + number: 536860000 + full_name: ".objc.protobuf.tests.test_all_types" + type: ".objc.protobuf.tests.TestAllTypes" + }]; } extend TestHugeFieldNumbers { diff --git a/src/google/protobuf/compiler/BUILD.bazel b/src/google/protobuf/compiler/BUILD.bazel index 7bbce08b4a..9cc302eb8d 100644 --- a/src/google/protobuf/compiler/BUILD.bazel +++ b/src/google/protobuf/compiler/BUILD.bazel @@ -311,6 +311,7 @@ cc_test( "//:protobuf", "//src/google/protobuf:cc_test_protos", "//src/google/protobuf:test_util2", + "//src/google/protobuf/compiler:retention", "//src/google/protobuf/io", "//src/google/protobuf/stubs", "//src/google/protobuf/testing", diff --git a/src/google/protobuf/compiler/cpp/unittest.inc b/src/google/protobuf/compiler/cpp/unittest.inc index bf434f55dd..4be035755e 100644 --- a/src/google/protobuf/compiler/cpp/unittest.inc +++ b/src/google/protobuf/compiler/cpp/unittest.inc @@ -70,6 +70,7 @@ #include "google/protobuf/arena.h" #include "google/protobuf/compiler/cpp/test_bad_identifiers.pb.h" #include "google/protobuf/compiler/importer.h" +#include "google/protobuf/compiler/retention.h" #include "google/protobuf/compiler/scc.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/dynamic_message.h" @@ -129,9 +130,10 @@ TEST(GENERATED_DESCRIPTOR_TEST_NAME, IdenticalDescriptors) { // Test that descriptors are generated correctly by converting them to // FileDescriptorProtos and comparing. - FileDescriptorProto generated_descriptor_proto, parsed_descriptor_proto; + FileDescriptorProto generated_descriptor_proto; generated_descriptor->CopyTo(&generated_descriptor_proto); - parsed_descriptor->CopyTo(&parsed_descriptor_proto); + FileDescriptorProto parsed_descriptor_proto = + compiler::StripSourceRetentionOptions(*parsed_descriptor); EXPECT_EQ(parsed_descriptor_proto.DebugString(), generated_descriptor_proto.DebugString()); diff --git a/src/google/protobuf/compiler/parser_unittest.cc b/src/google/protobuf/compiler/parser_unittest.cc index 8b6ed18220..b0b7d334cc 100644 --- a/src/google/protobuf/compiler/parser_unittest.cc +++ b/src/google/protobuf/compiler/parser_unittest.cc @@ -50,6 +50,7 @@ #include "absl/memory/memory.h" #include "absl/strings/str_join.h" #include "absl/strings/substitute.h" +#include "google/protobuf/compiler/retention.h" #include "google/protobuf/test_util2.h" #include "google/protobuf/unittest.pb.h" #include "google/protobuf/unittest_custom_options.pb.h" @@ -2421,11 +2422,29 @@ void StripFieldTypeName(FileDescriptorProto* file_proto) { } } +void StripEmptyOptions(DescriptorProto& proto) { + for (auto& ext : *proto.mutable_extension_range()) { + if (ext.has_options() && ext.options().DebugString().empty()) { + ext.clear_options(); + } + } +} + +void StripEmptyOptions(FileDescriptorProto& file_proto) { + if (file_proto.message_type_size() == 0) { + return; + } + for (auto& msg : *file_proto.mutable_message_type()) { + StripEmptyOptions(msg); + } +} + TEST_F(ParseDescriptorDebugTest, TestAllDescriptorTypes) { const FileDescriptor* original_file = protobuf_unittest::TestAllTypes::descriptor()->file(); FileDescriptorProto expected; original_file->CopyTo(&expected); + StripEmptyOptions(expected); // Get the DebugString of the unittest.proto FileDecriptor, which includes // all other descriptor types diff --git a/src/google/protobuf/unittest.proto b/src/google/protobuf/unittest.proto index d3025876b8..deb9d3119f 100644 --- a/src/google/protobuf/unittest.proto +++ b/src/google/protobuf/unittest.proto @@ -1134,7 +1134,11 @@ message TestHugeFieldNumbers { bytes oneof_bytes = 536870014; } - extensions 536860000 to 536869999; + extensions 536860000 to 536869999 [declaration = { + number: 536860000 + full_name: ".protobuf_unittest.test_all_types" + type: ".protobuf_unittest.TestAllTypes" + }]; } extend TestHugeFieldNumbers { diff --git a/src/google/protobuf/unittest_lite.proto b/src/google/protobuf/unittest_lite.proto index e2730c6419..b594b6f6ad 100644 --- a/src/google/protobuf/unittest_lite.proto +++ b/src/google/protobuf/unittest_lite.proto @@ -455,7 +455,11 @@ message TestHugeFieldNumbersLite { bytes oneof_bytes = 536870014; } - extensions 536860000 to 536869999; + extensions 536860000 to 536869999 [declaration = { + number: 536860000 + full_name: ".protobuf_unittest.test_all_types_lite" + type: ".protobuf_unittest.TestAllTypesLite" + }]; } extend TestHugeFieldNumbersLite { diff --git a/src/google/protobuf/unittest_mset_wire_format.proto b/src/google/protobuf/unittest_mset_wire_format.proto index de73d74fd5..022868e4f5 100644 --- a/src/google/protobuf/unittest_mset_wire_format.proto +++ b/src/google/protobuf/unittest_mset_wire_format.proto @@ -46,7 +46,14 @@ option csharp_namespace = "Google.ProtocolBuffers.TestProtos"; message TestMessageSet { option message_set_wire_format = true; - extensions 4 to max; + extensions 4 to 529999999; + + extensions 530000000 to max + [declaration = { + number: 1952731290, + full_name: ".protobuf_unittest_v1api.TestMessageSetExtension3.message_set_extension", + type: ".protobuf_unittest_v1api.TestMessageSetExtension3" + }]; } message TestMessageSetWireFormatContainer {