protobuf.js icon indicating copy to clipboard operation
protobuf.js copied to clipboard

Missing valuesOptions in fromJSON parser function

Open dobrac opened this issue 1 year ago • 0 comments

Hi! 👋

I've found out the "valuesOptions" option in Enum class is missing when parsed from the JSON.

Reproduction:

  • Create .proto file containing an enum with the valuesOptions
  • Generate JSON from this .proto file
  • Parse the generated JSON back
  • Try to access the valuesOptions field in that enum

The following code change should fix it:

diff --git a/node_modules/protobufjs/src/enum.js b/node_modules/protobufjs/src/enum.js
index 1c01620..730b8e4 100644
--- a/node_modules/protobufjs/src/enum.js
+++ b/node_modules/protobufjs/src/enum.js
@@ -87,7 +87,7 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
  * @throws {TypeError} If arguments are invalid
  */
 Enum.fromJSON = function fromJSON(name, json) {
-    var enm = new Enum(name, json.values, json.options, json.comment, json.comments);
+    var enm = new Enum(name, json.values, json.options, json.comment, json.comments, json.valuesOptions);
     enm.reserved = json.reserved;
     return enm;
 };

This issue body was partially generated by patch-package.

dobrac avatar Jan 13 '24 13:01 dobrac