Skip to content

Commit 5004250

Browse files
committed
Merge branch 'pr/110'
GODRIVER-675 GODRIVER-676 Change-Id: Ibb3f16d108b177ce6b31e6f7b3b4b741dc779c2b
2 parents 1e8b9e5 + 3d3601d commit 5004250

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

bson/bsoncodec/struct_codec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func (sc *StructCodec) isZero(i interface{}) bool {
222222
return true
223223
}
224224

225-
if z, ok := v.Interface().(Zeroer); ok {
225+
if z, ok := v.Interface().(Zeroer); ok && (v.Kind() != reflect.Ptr || !v.IsNil()) {
226226
return z.IsZero()
227227
}
228228

bson/bsoncodec/struct_codec_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package bsoncodec
88

99
import (
1010
"testing"
11+
"time"
1112

1213
"github.com/stretchr/testify/assert"
1314
)
@@ -35,4 +36,12 @@ func TestZeoerInterfaceUsedByDecoder(t *testing.T) {
3536

3637
z.reportZero = true
3738
assert.True(t, enc.isZero(z))
39+
40+
// *time.Time with nil should be zero
41+
var tp *time.Time
42+
assert.True(t, enc.isZero(tp))
43+
44+
// actually all zeroer if nil should also be zero
45+
var zp *zeroTest
46+
assert.True(t, enc.isZero(zp))
3847
}

0 commit comments

Comments
 (0)