Prevent early return in proto-loader containsDefinition

f289c343b3 introduced a bug - the
recursive for-loop descended into the first elements nested array
and returned that value without iterating over the other members
of the array. This means that the code would only work correctly
when the protofile contained a definition whose name was alphabetically
first amongst its siblings.

This commit fixes the issue by moving the call to containsDefinition
into the if statement to allow iteration to continue if
containsDefinition returns false.
This commit is contained in:
Mike Lewis 2021-06-28 19:04:58 +01:00
parent f87744b917
commit 41e09f7d12
No known key found for this signature in database
GPG Key ID: 3759CCC778AF5587
1 changed files with 2 additions and 2 deletions

View File

@ -583,8 +583,8 @@ function containsDefinition(definitionType: typeof Protobuf.Type | typeof Protob
for (const nested of namespace.nestedArray.sort(compareName)) {
if (nested instanceof definitionType) {
return true;
} else if (isNamespaceBase(nested) && !(nested instanceof Protobuf.Type) && !(nested instanceof Protobuf.Enum)) {
return containsDefinition(definitionType, nested);
} else if (isNamespaceBase(nested) && !(nested instanceof Protobuf.Type) && !(nested instanceof Protobuf.Enum) && containsDefinition(definitionType, nested)) {
return true;
}
}