A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/protocolbuffers/protobuf/commit/694eedd395e2f5bcc4d0dfe28f0ef80efb80edd7 below:

Remove CollectExtensions check banning unknown custom options since u… · protocolbuffers/protobuf@694eedd · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+24

-18

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+24

-18

lines changed Original file line number Diff line number Diff line change

@@ -70,14 +70,11 @@ using FieldDescriptorSet =

70 70

// Recursively searches the given message to collect extensions.

71 71

// Returns true if all the extensions can be recognized. The extensions will be

72 72

// appended in to the extensions parameter.

73 -

// Returns false when there are unknown fields, in which case the data in the

74 -

// extensions output parameter is not reliable and should be discarded.

75 -

bool CollectExtensions(const Message& message, FieldDescriptorSet* extensions) {

73 +

// Unknown extensions may be present in the case of option imports and will be

74 +

// ignored.

75 +

void CollectExtensions(const Message& message, FieldDescriptorSet* extensions) {

76 76

const Reflection* reflection = message.GetReflection();

77 77 78 -

// There are unknown fields that could be extensions, thus this call fails.

79 -

if (reflection->GetUnknownFields(message).field_count() > 0) return false;

80 - 81 78

std::vector<const FieldDescriptor*> fields;

82 79

reflection->ListFields(message, &fields);

83 80

@@ -92,16 +89,14 @@ bool CollectExtensions(const Message& message, FieldDescriptorSet* extensions) {

92 89

for (int j = 0; j < size; j++) {

93 90

const Message& sub_message =

94 91

reflection->GetRepeatedMessage(message, fields[i], j);

95 -

if (!CollectExtensions(sub_message, extensions)) return false;

92 +

CollectExtensions(sub_message, extensions);

96 93

}

97 94

} else {

98 95

const Message& sub_message = reflection->GetMessage(message, fields[i]);

99 -

if (!CollectExtensions(sub_message, extensions)) return false;

96 +

CollectExtensions(sub_message, extensions);

100 97

}

101 98

}

102 99

}

103 - 104 -

return true;

105 100

}

106 101 107 102

// Finds all extensions for custom options in the given file descriptor with the

@@ -115,7 +110,7 @@ void CollectExtensions(const FileDescriptor& file,

115 110

file_proto.GetDescriptor()->full_name());

116 111 117 112

// descriptor.proto is not found in the builder pool, meaning there are no

118 -

// custom options.

113 +

// custom options or they are option imported and not reachable.

119 114

if (file_proto_desc == nullptr) return;

120 115 121 116

DynamicMessageFactory factory;

@@ -124,14 +119,10 @@ void CollectExtensions(const FileDescriptor& file,

124 119

ABSL_CHECK(dynamic_file_proto.get() != nullptr);

125 120

ABSL_CHECK(dynamic_file_proto->ParseFromString(file_data));

126 121 127 -

// Collect the extensions again from the dynamic message.

122 +

// Collect the extensions from the dynamic message.

128 123

extensions->clear();

129 -

ABSL_CHECK(CollectExtensions(*dynamic_file_proto, extensions))

130 -

<< "Found unknown fields in FileDescriptorProto when building "

131 -

<< file_proto.name()

132 -

<< ". It's likely that those fields are custom options, however, "

133 -

"those options cannot be recognized in the builder pool. "

134 -

"This normally should not happen. Please report a bug.";

124 +

// Unknown extensions are ok and expected in the case of option imports.

125 +

CollectExtensions(*dynamic_file_proto, extensions);

135 126

}

136 127 137 128

// Our static initialization methods can become very, very large.

Original file line number Diff line number Diff line change

@@ -10,6 +10,7 @@

10 10

#include <memory>

11 11

#include <string>

12 12 13 +

#include "google/protobuf/testing/file.h"

13 14

#include "google/protobuf/testing/file.h"

14 15

#include "google/protobuf/testing/file.h"

15 16

#include "google/protobuf/descriptor.pb.h"

@@ -19,13 +20,15 @@

19 20

#include "google/protobuf/compiler/java/java_features.pb.h"

20 21

#include "google/protobuf/compiler/command_line_interface_tester.h"

21 22 23 + 22 24

namespace google {

23 25

namespace protobuf {

24 26

namespace compiler {

25 27

namespace java {

26 28

namespace {

27 29 28 30

#define PACKAGE_PREFIX ""

31 +

#define PACKAGE_IMPORT_PREFIX ""

29 32 30 33

class JavaGeneratorTest : public CommandLineInterfaceTester {

31 34

protected:

@@ -45,6 +48,16 @@ class JavaGeneratorTest : public CommandLineInterfaceTester {

45 48

std::string path = absl::StrCat(temp_directory(), "/", filename);

46 49

return File::Exists(path);

47 50

}

51 + 52 +

bool FileContainsSubstring(absl::string_view filename,

53 +

absl::string_view substring) {

54 +

std::string path = absl::StrCat(temp_directory(), "/", filename);

55 +

std::string contents;

56 +

if (!File::GetContents(path, &contents, true).ok()) {

57 +

return false;

58 +

}

59 +

return contents.find(substring) != std::string::npos;

60 +

}

48 61

};

49 62 50 63

TEST_F(JavaGeneratorTest, Basic) {

@@ -365,6 +378,8 @@ TEST_F(JavaGeneratorTest,

365 378

"class name, \"TestFileNameProto\", matches the name "

366 379

"of one of the types declared inside it");

367 380

}

381 + 382 + 368 383

} // namespace

369 384

} // namespace java

370 385

} // namespace compiler

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4