merged fix from RC_0_16

This commit is contained in:
Arvid Norberg 2013-10-24 07:22:44 +00:00
parent af6dbc5d79
commit c94ed806db
6 changed files with 38 additions and 6 deletions

View File

@ -25,6 +25,7 @@
* fix uTP edge case where udp socket buffer fills up
* fix nagle implementation in uTP
* fix issue when loading certain malformed .torrent files
* pass along host header with http proxy requests and possible http_connection shutdown hang
0.16.12 release

View File

@ -409,16 +409,33 @@ namespace libtorrent
std::string extension(std::string const& f)
{
char const* ext = strrchr(f.c_str(), '.');
if (ext == 0) return "";
return ext;
for (int i = f.size() - 1; i >= 0; --i)
{
if (f[i] == '/') break;
#ifdef TORRENT_WINDOWS
if (f[i] == '\\') break;
#endif
if (f[i] != '.') continue;
return f.substr(i);
}
return "";
}
void replace_extension(std::string& f, std::string const& ext)
{
char const* e = strrchr(f.c_str(), '.');
if (e == 0) f += '.';
else f.resize(e - f.c_str() + 1);
for (int i = f.size() - 1; i >= 0; --i)
{
if (f[i] == '/') break;
#ifdef TORRENT_WINDOWS
if (f[i] == '\\') break;
#endif
if (f[i] != '.') continue;
f.resize(i);
break;
}
f += '.';
f += ext;
}

View File

@ -308,6 +308,8 @@ namespace libtorrent
if (p->list_at(i)->type() != lazy_entry::string_t)
return false;
std::string path_element = p->list_at(i)->string_value();
if (path_element.empty())
path_element = "_";
if (!valid_path_element(path_element)) continue;
if (i == end - 1) *filename = p->list_at(i);
trim_path_element(path_element);

View File

@ -125,6 +125,7 @@ int test_main()
TEST_EQUAL(extension("blah.exe"), ".exe");
TEST_EQUAL(extension("blah.foo.bar"), ".bar");
TEST_EQUAL(extension("blah.foo."), ".");
TEST_EQUAL(extension("blah.foo/bar"), "");
TEST_EQUAL(filename("blah"), "blah");
TEST_EQUAL(filename("/blah/foo/bar"), "bar");
@ -209,6 +210,15 @@ int test_main()
replace_extension(test, "txt");
TEST_EQUAL(test, "foo.txt");
test = "_";
replace_extension(test, "txt");
TEST_EQUAL(test, "_.txt");
test = "1.2.3/_";
replace_extension(test, "txt");
TEST_EQUAL(test, "1.2.3/_.txt");
// file class
file f;
#if TORRENT_USE_UNC_PATHS || !defined WIN32

View File

@ -71,6 +71,7 @@ test_torrent_t test_torrents[] =
{ "url_seed_multi_space.torrent" },
{ "url_seed_multi_space_nolist.torrent" },
{ "root_hash.torrent" },
{ "empty_path_multi.torrent" },
};
struct test_failing_torrent_t

View File

@ -0,0 +1 @@
d10:created by10:libtorrent13:creation datei1359599503e4:infod5:filesld6:lengthi425e4:pathl5:abcdeeed6:lengthi3e4:pathl0:eed6:lengthi5e4:pathl0:eee4:name4:temp12:piece lengthi16384e6:pieces20:‚ž¼Œ&¾ÇJW}ÜA4u,·¼‡ee