add throwing overload of parse_magnet_uri

This commit is contained in:
arvidn 2017-11-05 17:11:28 +01:00 committed by Arvid Norberg
parent d2bf34632c
commit a690e6c76d
3 changed files with 16 additions and 1 deletions

View File

@ -79,8 +79,10 @@ namespace libtorrent {
#endif
// This function parses out information from the magnet link and populates the
// add_torrent_params object.
// add_torrent_params object. The overload that does not take an
// ``error_code`` reference will throw a system_error on error
TORRENT_EXPORT add_torrent_params parse_magnet_uri(string_view uri, error_code& ec);
TORRENT_EXPORT add_torrent_params parse_magnet_uri(string_view uri);
}
#endif

View File

@ -299,4 +299,12 @@ namespace libtorrent {
if (!name.empty()) p.name = name;
return p;
}
add_torrent_params parse_magnet_uri(string_view uri)
{
error_code ec;
add_torrent_params ret = parse_magnet_uri(uri, ec);
if (ec) aux::throw_ex<system_error>(ec);
return ret;
}
}

View File

@ -250,6 +250,11 @@ TORRENT_TEST(parse_invalid_escaped_hash_parameter)
TEST_EQUAL(ec, error_code(errors::invalid_escaped_string));
}
TORRENT_TEST(throwing_overload)
{
TEST_THROW(parse_magnet_uri("magnet:?xt=urn%%3A"));
}
TORRENT_TEST(parse_missing_hash)
{
// parse_magnet_uri