Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dagcbor: coerce undef to null. #308

Merged
merged 2 commits into from
Dec 7, 2021
Merged

Commits on Dec 6, 2021

  1. dagcbor: coerce undef to null.

    CBOR's "undefined" token -- byte 23;
    see https://datatracker.ietf.org/doc/html/rfc8949#section-5.7
    or https://datatracker.ietf.org/doc/html/rfc8949#section-3.3 table 4 --
    is not generally considered part of DAG-CBOR (which is generally a
    subset of CBOR).
    
    However, it may be desirable to allow parsing data flagged as DAG-CBOR
    while coercing any "undefined" tokens to a "null", even if considering it
    noncanonical.
    
    Because DAG-CBOR was not well specified early on, and because libraries
    existed for a considerable period of time which would readily emit data
    that we would not call DAG-CBOR, data exists in the wild which encoded
    these tokens, and links to them with an indicator that it's DAG-CBOR.
    We may wish to continue allowing these documents to be parsed.
    
    This does *not* mean that our DAG-CBOR codec will emit "undefined" tokens.
    That would not be neither canonical nor valid DAG-CBOR, so we don't want to;
    and it would also not be possible to describe with this library in the first place
    (it's not in the IPLD data model; so how would you?).
    
    This does *not* mean that you can *read* DAG-CBOR data with this codec
    and see "undefined" tokens distinctly.  Again, they're not in the IPLD data model,
    so this library API (intentionally) does not have the ability to describe that.
    With this change, an "undefined" token will be allowed by the parser, but will
    be described as "null" in terms of the IPLD data model, and not be distinguishable
    from any other null.
    
    A change to the DAG-CBOR specs may be required if we decide to embrace
    this behavior and expansion of what we consider non-canonical-but-valid DAG-CBOR.
    warpfork committed Dec 6, 2021
    Configuration menu
    Copy the full SHA
    8bac660 View commit details
    Browse the repository at this point in the history

Commits on Dec 7, 2021

  1. dagcbor: test that undefined token parses and becomes treated as null.

    (Made a one-off test for this.  It should also be a fixture in
    the ipld/ipld metarepo, but we don't already have those wired up,
    so I'm making the more incremental diff today.)
    warpfork committed Dec 7, 2021
    Configuration menu
    Copy the full SHA
    0683bbe View commit details
    Browse the repository at this point in the history