bencode: Encoding nil interfaces are an error except at data root
This commit is contained in:
parent
1a4fbed1ac
commit
1fb64de07c
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue