Skip to content

Commit

Permalink
dagcbor: test that undefined token parses and becomes treated as null.
Browse files Browse the repository at this point in the history
(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.)
  • Loading branch information
warpfork committed Dec 7, 2021
1 parent 8bac660 commit 0683bbe
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions codec/dagcbor/unmarshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
})
}

0 comments on commit 0683bbe

Please sign in to comment.