diff --git a/codec/dagcbor/unmarshal_test.go b/codec/dagcbor/unmarshal_test.go index 7d6557df..d0a8d815 100644 --- a/codec/dagcbor/unmarshal_test.go +++ b/codec/dagcbor/unmarshal_test.go @@ -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) + }) }