Merge pull request #240 from mrd0ll4r/bencode-dict-fix

http/bencode: add missing []Dict case
This commit is contained in:
mrd0ll4r 2016-10-01 20:22:27 +02:00 committed by GitHub
commit 6ed89f1b91
2 changed files with 9 additions and 0 deletions

View file

@ -89,6 +89,13 @@ func marshal(w io.Writer, data interface{}) (err error) {
case []interface{}:
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:
return fmt.Errorf("attempted to marshal unsupported type:\n%T", v)
}

View file

@ -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{}{}, []string{"de"}},
{[]Dict{{"a": "b"}, {"c": "d"}}, []string{"ld1:a1:bed1:c1:dee", "ld1:c1:ded1:a1:bee"}},
}
func TestMarshal(t *testing.T) {