add trailing slash (#1969)

This commit is contained in:
Pavel Pimenov 2017-05-05 00:35:00 +03:00 committed by Arvid Norberg
parent 76ef0babed
commit 11c75da314
5 changed files with 14 additions and 7 deletions

View File

@ -53,6 +53,11 @@ namespace libtorrent {
// internal // internal
inline bool is_digit(char c) inline bool is_digit(char c)
{ return c >= '0' && c <= '9'; } { return c >= '0' && c <= '9'; }
inline void ensure_trailing_slash(std::string& url)
{
if (url.empty() || url[url.size() - 1] != '/')
url += '/';
}
TORRENT_EXTRA_EXPORT bool is_print(char c); TORRENT_EXTRA_EXPORT bool is_print(char c);
TORRENT_EXTRA_EXPORT bool is_space(char c); TORRENT_EXTRA_EXPORT bool is_space(char c);

View File

@ -121,8 +121,7 @@ namespace libtorrent {
// however, we may still need to insert a '/' in case neither side // however, we may still need to insert a '/' in case neither side
// has one. We know the location doesn't start with a / already. // has one. We know the location doesn't start with a / already.
// so, if the referrer doesn't end with one, add it. // so, if the referrer doesn't end with one, add it.
if (url.empty() || url[url.size() - 1] != '/') ensure_trailing_slash(url);
url += '/';
url += location; url += location;
} }
return url; return url;

View File

@ -265,7 +265,8 @@ namespace libtorrent {
// correct URLs to end with a "/" for multi-file torrents // correct URLs to end with a "/" for multi-file torrents
std::string& url = ws.back().url; std::string& url = ws.back().url;
if (multi_file && url[url.size()-1] != '/') url += '/'; if (multi_file)
ensure_trailing_slash(url);
} }
for (auto const& e : p.http_seeds) for (auto const& e : p.http_seeds)

View File

@ -1460,7 +1460,8 @@ namespace libtorrent {
{ {
web_seed_entry ent(maybe_url_encode(url_seeds.string_value().to_string()) web_seed_entry ent(maybe_url_encode(url_seeds.string_value().to_string())
, web_seed_entry::url_seed); , web_seed_entry::url_seed);
if ((m_flags & multifile) && ent.url[ent.url.size() - 1] != '/') ent.url += '/'; if (m_flags & multifile)
ensure_trailing_slash(ent.url);
m_web_seeds.push_back(ent); m_web_seeds.push_back(ent);
} }
else if (url_seeds && url_seeds.type() == bdecode_node::list_t) else if (url_seeds && url_seeds.type() == bdecode_node::list_t)
@ -1474,7 +1475,8 @@ namespace libtorrent {
if (url.string_length() == 0) continue; if (url.string_length() == 0) continue;
web_seed_entry ent(maybe_url_encode(url.string_value().to_string()) web_seed_entry ent(maybe_url_encode(url.string_value().to_string())
, web_seed_entry::url_seed); , web_seed_entry::url_seed);
if ((m_flags & multifile) && ent.url[ent.url.size() - 1] != '/') ent.url += '/'; if (m_flags & multifile)
ensure_trailing_slash(ent.url);
if (!unique.insert(ent.url).second) continue; if (!unique.insert(ent.url).second) continue;
m_web_seeds.push_back(ent); m_web_seeds.push_back(ent);
} }

View File

@ -95,8 +95,8 @@ web_peer_connection::web_peer_connection(peer_connection_args const& pack
{ {
// handle incorrect .torrent files which are multi-file // handle incorrect .torrent files which are multi-file
// but have web seeds not ending with a slash // but have web seeds not ending with a slash
if (m_path.empty() || m_path[m_path.size() - 1] != '/') m_path += '/'; ensure_trailing_slash(m_path);
if (m_url.empty() || m_url[m_url.size() - 1] != '/') m_url += '/'; ensure_trailing_slash(m_url);
} }
else else
{ {