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.)
@@ -4,6 +4,8 @@ import (
"strings"
"testing"
+ "github.com/ipld/go-ipld-prime/datamodel"
+
qt "github.com/frankban/quicktest"
"github.com/ipld/go-ipld-prime/node/basicnode"
@@ -38,4 +40,13 @@ func TestFunBlocks(t *testing.T) {
err := Decode(nb, buf)
qt.Assert(t, err, qt.Equals, ErrAllocationBudgetExceeded)
})
+ t.Run("undef", func(t *testing.T) {
+ // This fixture tests that we tolerate cbor's "undefined" token (even though it's noncanonical and you shouldn't use it),
+ // and that it becomes a null in the data model level.
+ buf := strings.NewReader("\xf7")
+ nb := basicnode.Prototype.Any.NewBuilder()
+ err := Decode(nb, buf)
+ qt.Assert(t, err, qt.IsNil)
+ qt.Assert(t, nb.Build().Kind(), qt.Equals, datamodel.Kind_Null)
+ })
}
