criccomini / proto-schema-parser

A Pure Python Protobuf Parser
MIT License
38 stars 20 forks source link

Throws an error when an enum has hexadecimal values #28

Closed alufers closed 3 months ago

alufers commented 3 months ago

Hi,

This parser throws an error when an enum value is written in hexadecimal instead of decimal. Here is a simple test case:

from proto_schema_parser.parser import Parser

text = """
syntax = "proto2";

enum some_enum {
  SOME_VALUE = 0xC8;
}
"""

result = Parser().parse(text)

And the error:

  File "/home/.../lib/python3.12/site-packages/proto_schema_parser/parser.py", line 176, in visitEnumValueDecl
    number = int(self._getText(ctx.enumValueNumber()))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '0xC8'

The included protobuf code compiles fine with the first-party protobuf compiler.

criccomini commented 3 months ago

PR:

https://github.com/recap-build/proto-schema-parser/pull/29

criccomini commented 3 months ago

Fix has been published to 1.3.5:

https://pypi.org/project/proto-schema-parser/1.3.5/