File tree Expand file tree Collapse file tree 2 files changed +20
-8
lines changed Expand file tree Collapse file tree 2 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -5173,6 +5173,21 @@ absl::Status DescriptorPool::SetFeatureSetDefaults(FeatureSetDefaults spec) {
5173
5173
return absl::OkStatus ();
5174
5174
}
5175
5175
5176
+ bool DescriptorPool::ShouldEnforceExtensionDeclaration (
5177
+ const FieldDescriptor& field) const {
5178
+ ABSL_DCHECK (field.is_extension ());
5179
+ const Descriptor* containing_type = field.containing_type ();
5180
+ switch (enforce_extension_declarations_) {
5181
+ case ExtDeclEnforcementLevel::kCustomExtensions :
5182
+ return containing_type->file ()->name () !=
5183
+ " google/protobuf/descriptor.proto" ;
5184
+ case ExtDeclEnforcementLevel::kAllExtensions :
5185
+ return true ;
5186
+ default :
5187
+ return false ;
5188
+ }
5189
+ }
5190
+
5176
5191
const FeatureSetDefaults& DescriptorPool::GetFeatureSetDefaults () const {
5177
5192
if (feature_set_defaults_spec_ != nullptr ) return *feature_set_defaults_spec_;
5178
5193
static const FeatureSetDefaults* cpp_default_spec =
@@ -8717,7 +8732,9 @@ void DescriptorBuilder::ValidateOptions(const FieldDescriptor* field,
8717
8732
return ;
8718
8733
}
8719
8734
8720
- if (pool_->EnforceCustomExtensionDeclarations ()) {
8735
+ // TODO: b/396020109 - Check for MessageSet extensions in separate .txtpb
8736
+ // file.
8737
+ if (pool_->ShouldEnforceExtensionDeclaration (*field)) {
8721
8738
for (const auto & declaration : extension_range->options_ ->declaration ()) {
8722
8739
if (declaration.number () != field->number ()) continue ;
8723
8740
if (declaration.reserved ()) {
Original file line number Diff line number Diff line change @@ -2386,17 +2386,12 @@ class PROTOBUF_EXPORT DescriptorPool {
2386
2386
enforce_extension_declarations_ = enforce;
2387
2387
}
2388
2388
2389
- bool EnforceDescriptorExtensionDeclarations () const {
2389
+ bool ShouldEnforceDescriptorExtensionDeclarations () const {
2390
2390
return enforce_extension_declarations_ ==
2391
2391
ExtDeclEnforcementLevel::kAllExtensions ;
2392
2392
}
2393
2393
2394
- bool EnforceCustomExtensionDeclarations () const {
2395
- return enforce_extension_declarations_ ==
2396
- ExtDeclEnforcementLevel::kAllExtensions ||
2397
- enforce_extension_declarations_ ==
2398
- ExtDeclEnforcementLevel::kCustomExtensions ;
2399
- }
2394
+ bool ShouldEnforceExtensionDeclaration (const FieldDescriptor& field) const ;
2400
2395
2401
2396
#ifndef SWIG
2402
2397
// Dispatch recursive builds to a callback that may stick them onto a separate
You can’t perform that action at this time.
0 commit comments