rgrinberg / bencode

Bencode (.torrent file format) reader/writer in OCaml
24 stars 4 forks source link

Make the bencode encoder/decoder isomorphic and complient to the specification #16

Closed kit-ty-kate closed 4 months ago

kit-ty-kate commented 4 months ago

The spec notes:

Integers are represented by an 'i' followed by the number in base 10 followed by an 'e'. For example i3e corresponds to 3 and i-3e corresponds to -3. Integers have no size limitation. i-0e is invalid. All encodings with a leading zero, such as i03e, are invalid, other than i0e, which of course corresponds to 0.

This PR makes sure leading 0s as well as -0 are not accepted.

While this is not specified, the same thing was done for strings to ensure isomorphism between encoder/decoder. Whitespaces are also not specified in the specs so for the same reason I removed support for them.

Related to https://github.com/rgrinberg/bencode/issues/15#issuecomment-2075448486

rgrinberg commented 4 months ago

Thanks