r1chardj0n3s / parse

Parse strings using a specification based on the Python format() syntax.
http://pypi.python.org/pypi/parse
MIT License
1.71k stars 101 forks source link

Length specification is not properly handled with 'x' format character #149

Open crosser opened 1 year ago

crosser commented 1 year ago

I am using version 1.19.0 that is packaged with Ubuntu lunar.

I intend to use the same format string for formatting and for parsing strings that are made of a group of hexadecimal numbers of known fixed length. But I noticed that while length field works for 'd' format character, it does not seem to work correctly with 'x' format character:

>> a="{x:03d}{y:03d}"
>>> parse(a, a.format(x=1, y=2))
<Result () {'x': 1, 'y': 2}>
>>> b="{x:03x}{y:03x}"
>>> parse(b, b.format(x=1, y=2))
<Result () {'x': 256, 'y': 2}>

I think that this is a bug?...

wimglenn commented 1 year ago

Yes that looks bugged to me.