bencode/decode.go | 19 +++++++++++++++---- diff --git a/bencode/decode.go b/bencode/decode.go index 081a44a715ea7fc7e31d95790a1c8f39a863b9ae..8b22fa734f6f4f19fc26c6d1260d3210165b18e5 100644 --- a/bencode/decode.go +++ b/bencode/decode.go @@ -344,12 +344,23 @@ } func (d *Decoder) parseList(v reflect.Value) error { switch v.Kind() { - case reflect.Array, reflect.Slice: default: - return &UnmarshalTypeError{ - Value: "list", - Type: v.Type(), + // If the list is a singleton of the expected type, use that value. See + // https://github.com/anacrolix/torrent/issues/297. + l := reflect.New(reflect.SliceOf(v.Type())) + if err := d.parseList(l.Elem()); err != nil { + return err + } + if l.Elem().Len() != 1 { + return &UnmarshalTypeError{ + Value: "list", + Type: v.Type(), + } } + v.Set(l.Elem().Index(0)) + return nil + case reflect.Array, reflect.Slice: + // We can work with this. Normal case, fallthrough. } i := 0