From 5f27041c6e6b81b8b2ffb169c6dc45dc9eeab860 Mon Sep 17 00:00:00 2001 From: Marcus Svartmark Date: Fri, 24 Jan 2025 08:55:07 +0100 Subject: [PATCH] fix: Add check for existing array before reading When parsing a proto and handling oneofs there is no check if the array actually exists before reading it, causing the code to throw errors some times. This change add a check if the oneoffsArray exist before trying to read it. --- ext/descriptor/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/descriptor/index.js b/ext/descriptor/index.js index 6aafd2ab8..facef58ab 100644 --- a/ext/descriptor/index.js +++ b/ext/descriptor/index.js @@ -485,7 +485,7 @@ Field.prototype.toDescriptor = function toDescriptor(syntax) { // Handle part of oneof if (this.partOf) - if ((descriptor.oneofIndex = this.parent.oneofsArray.indexOf(this.partOf)) < 0) + if (this.parent.oneofsArray && (descriptor.oneofIndex = this.parent.oneofsArray.indexOf(this.partOf)) < 0) throw Error("missing oneof"); if (this.options) {