diff --git a/include/libtorrent/bencode.hpp b/include/libtorrent/bencode.hpp index 7e3a7848d..a31d3629a 100644 --- a/include/libtorrent/bencode.hpp +++ b/include/libtorrent/bencode.hpp @@ -215,9 +215,12 @@ namespace libtorrent ret += e.preformatted().size(); break; case entry::undefined_t: - // trying to encode a structure with uninitialized values! -// TORRENT_ASSERT_VAL(false, e.type()); - // do nothing + + // empty string + write_char(out, '0'); + write_char(out, ':'); + + ret += 2; break; } return ret; diff --git a/test/test_bencoding.cpp b/test/test_bencoding.cpp index 1502437fb..25661d486 100644 --- a/test/test_bencoding.cpp +++ b/test/test_bencoding.cpp @@ -121,6 +121,19 @@ TORRENT_TEST(preformatted_node) TEST_EQUAL(encode(e), "d4:infofoobare"); } +TORRENT_TEST(undefined_node) +{ + entry e(entry::undefined_t); + TEST_EQUAL(encode(e), "0:"); +} + +TORRENT_TEST(undefined_node2) +{ + entry e(entry::dictionary_t); + e["info"] = entry(entry::undefined_t); + TEST_EQUAL(encode(e), "d4:info0:e"); +} + #ifndef TORRENT_NO_DEPRECATE TORRENT_TEST(lazy_entry) {