Skip to content

Commit da9cbc7

Browse files
committed
metainfo: Omit empty Metainfo.InfoBytes
1 parent 163a63f commit da9cbc7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

metainfo/metainfo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
type MetaInfo struct {
12-
InfoBytes bencode.Bytes `bencode:"info"`
12+
InfoBytes bencode.Bytes `bencode:"info,omitempty"`
1313
Announce string `bencode:"announce,omitempty"`
1414
AnnounceList AnnounceList `bencode:"announce-list,omitempty"`
1515
Nodes []Node `bencode:"nodes,omitempty"`

metainfo/nodes_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package metainfo
22

33
import (
4+
"bytes"
45
"testing"
56

67
"github.com/stretchr/testify/assert"
@@ -61,3 +62,13 @@ func TestUnmarshalBadMetainfoNodes(t *testing.T) {
6162
err := bencode.Unmarshal([]byte("d5:nodesl1:ai42eee"), &mi)
6263
require.Error(t, err)
6364
}
65+
66+
func TestMetainfoEmptyInfoBytes(t *testing.T) {
67+
var buf bytes.Buffer
68+
require.NoError(t, (&MetaInfo{
69+
// Include a non-empty field that comes after "info".
70+
UrlList: []string{"hello"},
71+
}).Write(&buf))
72+
var mi MetaInfo
73+
require.NoError(t, bencode.Unmarshal(buf.Bytes(), &mi))
74+
}

0 commit comments

Comments
 (0)