Merge pull request #240 from mrd0ll4r/bencode-dict-fix
http/bencode: add missing []Dict case
This commit is contained in:
commit
6ed89f1b91
2 changed files with 9 additions and 0 deletions
|
@ -89,6 +89,13 @@ func marshal(w io.Writer, data interface{}) (err error) {
|
||||||
case []interface{}:
|
case []interface{}:
|
||||||
err = marshalList(w, v)
|
err = marshalList(w, v)
|
||||||
|
|
||||||
|
case []Dict:
|
||||||
|
var interfaceSlice = make([]interface{}, len(v))
|
||||||
|
for i, d := range v {
|
||||||
|
interfaceSlice[i] = d
|
||||||
|
}
|
||||||
|
err = marshalList(w, interfaceSlice)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("attempted to marshal unsupported type:\n%T", v)
|
return fmt.Errorf("attempted to marshal unsupported type:\n%T", v)
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ var marshalTests = []struct {
|
||||||
|
|
||||||
{map[string]interface{}{"one": "aa", "two": "bb"}, []string{"d3:one2:aa3:two2:bbe", "d3:two2:bb3:one2:aae"}},
|
{map[string]interface{}{"one": "aa", "two": "bb"}, []string{"d3:one2:aa3:two2:bbe", "d3:two2:bb3:one2:aae"}},
|
||||||
{map[string]interface{}{}, []string{"de"}},
|
{map[string]interface{}{}, []string{"de"}},
|
||||||
|
|
||||||
|
{[]Dict{{"a": "b"}, {"c": "d"}}, []string{"ld1:a1:bed1:c1:dee", "ld1:c1:ded1:a1:bee"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMarshal(t *testing.T) {
|
func TestMarshal(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue