Nullus157 / cbor-diag-rs

Support for parsing/encoding CBOR diagnostic notation and annotated hex
https://cbor.nemo157.com
Apache License 2.0
10 stars 6 forks source link

Whitespace within b64 string not accepted #108

Closed BrianSipos closed 2 years ago

BrianSipos commented 3 years ago

Currently the cbor2diag tool seems to treat whitespace within hex-encoded bytestrings differently than for base64-encoded bytestrings. An example of bad behavior is below. It seems that the where the space is in the base64 sequence doesn't matter. Any space causes this issue.

Section G.1 of RFC 8610 indicates that all whitespace is ingored. Its examples uses hex encoding but my interpretation it it should also apply to base64 encoding.

[STRIP ~]$ echo "h'6865  6C6C 6F'" | diag2pretty.rb
45            # bytes(5)
   68656c6c6f # "hello"
[STRIP ~]$ echo "b64'aGVsbG8='" | diag2pretty.rb
45            # bytes(5)
   68656c6c6f # "hello"
[STRIP ~]$ echo "b64'aGVs bG8='" | diag2pretty.rb
*** can't parse b64'aGVs bG8='
*** Expected one of [0-9a-zA-Z_\-+/], [=], "'" at line 1, column 9 (byte 9) after b64'aGVs
Nemo157 commented 3 years ago

cbor2diag is actually a different tool, hosted at https://github.com/cabo/cbor-diag

But, this is still interesting for me as cbor-diag fails on all those test cases 😓. It seems I missed support for base64 padding in the parser, and don't support whitespace in either string.

I would agree that the whitespace allowed in EDN by G.1 applies to all 3 prefixed byte string variants.

BrianSipos commented 3 years ago

Whoops! Thanks for the link.