bencode: Encoding nil interfaces are an error except at data root

This commit is contained in:
Matt Joiner 2015-10-23 12:35:38 +11:00
parent 1a4fbed1ac
commit 1fb64de07c
2 changed files with 4 additions and 4 deletions

View File

@ -33,6 +33,9 @@ type encoder struct {
}
func (e *encoder) encode(v interface{}) (err error) {
if v == nil {
return
}
defer func() {
if e := recover(); e != nil {
if _, ok := e.(runtime.Error); ok {
@ -106,9 +109,6 @@ func (e *encoder) reflect_marshaler(v reflect.Value) bool {
}
func (e *encoder) reflect_value(v reflect.Value) {
if !v.IsValid() {
return
}
if e.reflect_marshaler(v) {
return

View File

@ -73,7 +73,7 @@ var random_encode_tests = []random_encode_test{
func TestRandomEncode(t *testing.T) {
for _, test := range random_encode_tests {
data, err := Marshal(test.value)
assert.NoError(t, err)
assert.NoError(t, err, "%s", test)
assert.EqualValues(t, test.expected, string(data))
}
}