diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index fa397b7cd..9da7f9a77 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -1475,8 +1475,7 @@ namespace libtorrent { web_seed_entry ent(maybe_url_encode(url.string_value().to_string()) , web_seed_entry::url_seed); if ((m_flags & multifile) && ent.url[ent.url.size() - 1] != '/') ent.url += '/'; - if (unique.count(ent.url)) continue; - unique.insert(ent.url); + if (!unique.insert(ent.url).second) continue; m_web_seeds.push_back(ent); } } @@ -1497,9 +1496,8 @@ namespace libtorrent { { bdecode_node const url = http_seeds.list_at(i); if (url.type() != bdecode_node::string_t || url.string_length() == 0) continue; - std::string u = maybe_url_encode(url.string_value().to_string()); - if (unique.count(u)) continue; - unique.insert(u); + std::string const u = maybe_url_encode(url.string_value().to_string()); + if (!unique.insert(u).second) continue; m_web_seeds.push_back(web_seed_entry(u, web_seed_entry::http_seed)); } } diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index d06b05b3d..c9c8b565a 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -178,6 +178,30 @@ test_failing_torrent_t test_error_torrents[] = // TODO: torrent_info constructor that takes an invalid bencoded buffer // TODO: verify_encoding with a string that triggers character replacement +TORRENT_TEST(url_list_and_httpseeds) +{ + entry info; + info["pieces"] = "aaaaaaaaaaaaaaaaaaaa"; + info["name.utf-8"] = "test1"; + info["name"] = "test__"; + info["piece length"] = 16 * 1024; + info["length"] = 3245; + entry::list_type l; + l.push_back(entry("http://foo.com/bar1")); + l.push_back(entry("http://foo.com/bar1")); + l.push_back(entry("http://foo.com/bar2")); + entry const e(l); + entry torrent; + torrent["url-list"] = e; + torrent["httpseeds"] = e; + torrent["info"] = info; + std::vector buf; + bencode(std::back_inserter(buf), torrent); + error_code ec; + torrent_info ti(&buf[0], int(buf.size()), ec); + TEST_EQUAL(ti.web_seeds().size(), 4); +} + TORRENT_TEST(add_url_seed) { torrent_info ti(sha1_hash(" "));