Skip to content

Commit 4daf0f2

Browse files
author
iwysiu
committed
GODRIVER-1488 turn off DecodeDeepZeroInline for mgocompat.Registry (#312)
1 parent 5c748dd commit 4daf0f2

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

bson/mgocompat/bson_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,3 +1685,31 @@ func TestMarshalRespectNil(t *testing.T) {
16851685
assert.NotNil(t, testStruct2.Map, "expected non-nil map")
16861686
assert.NotNil(t, testStruct2.MapPtr, "expected non-nil map ptr")
16871687
}
1688+
1689+
// Our mgocompat.Registry tests
1690+
type Inner struct {
1691+
ID string
1692+
}
1693+
1694+
type InlineLoop struct {
1695+
Inner `bson:",inline"`
1696+
Value string
1697+
Draft *InlineLoop `bson:",omitempty"`
1698+
}
1699+
1700+
func TestInlineWithPointerToSelf(t *testing.T) {
1701+
x1 := InlineLoop{
1702+
Inner: Inner{
1703+
ID: "1",
1704+
},
1705+
Value: "",
1706+
}
1707+
1708+
bytes, err := bson.MarshalWithRegistry(Registry, x1)
1709+
assert.Nil(t, err, "expected nil error, got: %v", err)
1710+
1711+
var x2 InlineLoop
1712+
err = bson.UnmarshalWithRegistry(Registry, bytes, &x2)
1713+
assert.Nil(t, err, "expected nil error, got: %v", err)
1714+
assert.Equal(t, x1, x2, "Expected %v, got %v", x1, x2)
1715+
}

bson/mgocompat/registry.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ func NewRegistryBuilder() *bsoncodec.RegistryBuilder {
5050
structcodec, _ := bsoncodec.NewStructCodec(bsoncodec.DefaultStructTagParser,
5151
bsonoptions.StructCodec().
5252
SetDecodeZeroStruct(true).
53-
SetDecodeDeepZeroInline(true).
5453
SetEncodeOmitDefaultStruct(true).
5554
SetAllowUnexportedFields(true))
5655
emptyInterCodec := bsoncodec.NewEmptyInterfaceCodec(
@@ -94,7 +93,6 @@ func NewRespectNilValuesRegistryBuilder() *bsoncodec.RegistryBuilder {
9493
structcodec, _ := bsoncodec.NewStructCodec(bsoncodec.DefaultStructTagParser,
9594
bsonoptions.StructCodec().
9695
SetDecodeZeroStruct(true).
97-
SetDecodeDeepZeroInline(false).
9896
SetEncodeOmitDefaultStruct(true).
9997
SetAllowUnexportedFields(true))
10098
mapCodec := bsoncodec.NewMapCodec(

0 commit comments

Comments
 (0)