Skip to content

Parsing enums with complex options should work. #787

Open
@eventualbuddha

Description

@eventualbuddha

protobuf.js version: 6.7.3

Parsing enums with complex options should work. Currently it simply crashes when it gets into the RHS of the option, though not immediately. This is a sanitized version of a real proto used at my company, which seems to work fine with the Google protobuf tools but fails to parse with protobuf.js. I don't know protos that well so I am not exactly sure what the problem is.

This is part of a version 2 syntax file. The Protocol Buffer syntax definition for enums seems to indicate that the RHS of an option should be a constant. I don't know whether this qualifies, but like I said it works fine in our infrastructure.

enum AnEnum {
  LEGACY = 1 [
    (some.custom.option) = {
      type: {[an.api.type]: ITEM}, // crash on this line
      type: {[an.api.type]: PAGE},
    }
  ];
}
Error: illegal value '{' (line 4)
    at illegal (node_modules/protobufjs/src/parse.js:98:16)
    at readValue (node_modules/protobufjs/src/parse.js:137:19)
    at parseOptionValue (node_modules/protobufjs/src/parse.js:562:59)
    at parseOption (node_modules/protobufjs/src/parse.js:548:9)
    at parseInlineOptions (node_modules/protobufjs/src/parse.js:578:17)
    at parseEnumValue_line (node_modules/protobufjs/src/parse.js:525:13)
    at ifBlock (node_modules/protobufjs/src/parse.js:294:17)
    at parseEnumValue (node_modules/protobufjs/src/parse.js:515:9)
    at parseEnum_block (node_modules/protobufjs/src/parse.js:501:17)
    at ifBlock (node_modules/protobufjs/src/parse.js:290:17)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions