From 41e09f7d12b05d74f37e3fd30bf08a7398ad12d2 Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Mon, 28 Jun 2021 19:04:58 +0100 Subject: [PATCH] Prevent early return in proto-loader containsDefinition f289c343b3393aad73795c0657415f4160bcdcb5 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. --- packages/proto-loader/bin/proto-loader-gen-types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/proto-loader/bin/proto-loader-gen-types.ts b/packages/proto-loader/bin/proto-loader-gen-types.ts index fedaadc3..b441d425 100644 --- a/packages/proto-loader/bin/proto-loader-gen-types.ts +++ b/packages/proto-loader/bin/proto-loader-gen-types.ts @@ -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; } }