2009-05-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Use name.utf-8 and path.utf-8 key in higher priority than name and
	path key respectively when persing .torrent file.
	* src/BtContext.cc
	* src/BtContext.h
	* src/DefaultBtContext.cc
	* test/DefaultBtContextTest.cc
	* test/utf8.torrent
pull/1/head
Tatsuhiro Tsujikawa 2009-05-26 15:28:48 +00:00
parent 544732b124
commit 41df4b5e28
6 changed files with 44 additions and 2 deletions

View File

@ -1,3 +1,13 @@
2009-05-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Use name.utf-8 and path.utf-8 key in higher priority than name and
path key respectively when persing .torrent file.
* src/BtContext.cc
* src/BtContext.h
* src/DefaultBtContext.cc
* test/DefaultBtContextTest.cc
* test/utf8.torrent
2009-05-26 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2009-05-26 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added --xml-rpc-max-request-size option to limit the size of Added --xml-rpc-max-request-size option to limit the size of

View File

@ -38,12 +38,16 @@ namespace aria2 {
const std::string BtContext::C_NAME("name"); const std::string BtContext::C_NAME("name");
const std::string BtContext::C_NAME_UTF8("name.utf-8");
const std::string BtContext::C_FILES("files"); const std::string BtContext::C_FILES("files");
const std::string BtContext::C_LENGTH("length"); const std::string BtContext::C_LENGTH("length");
const std::string BtContext::C_PATH("path"); const std::string BtContext::C_PATH("path");
const std::string BtContext::C_PATH_UTF8("path.utf-8");
const std::string BtContext::C_INFO("info"); const std::string BtContext::C_INFO("info");
const std::string BtContext::C_PIECES("pieces"); const std::string BtContext::C_PIECES("pieces");

View File

@ -90,12 +90,16 @@ public:
static const std::string C_NAME; static const std::string C_NAME;
static const std::string C_NAME_UTF8;
static const std::string C_FILES; static const std::string C_FILES;
static const std::string C_LENGTH; static const std::string C_LENGTH;
static const std::string C_PATH; static const std::string C_PATH;
static const std::string C_PATH_UTF8;
static const std::string C_INFO; static const std::string C_INFO;
static const std::string C_PIECES; static const std::string C_PIECES;

View File

@ -117,7 +117,13 @@ void DefaultBtContext::extractFileEntries(const BDE& infoDict,
const std::deque<std::string>& urlList) const std::deque<std::string>& urlList)
{ {
if(overrideName.empty()) { if(overrideName.empty()) {
const BDE& nameData = infoDict[BtContext::C_NAME]; std::string nameKey;
if(infoDict.containsKey(BtContext::C_NAME_UTF8)) {
nameKey = BtContext::C_NAME_UTF8;
} else {
nameKey = BtContext::C_NAME;
}
const BDE& nameData = infoDict[nameKey];
if(nameData.isString()) { if(nameData.isString()) {
name = nameData.s(); name = nameData.s();
} else { } else {
@ -146,7 +152,13 @@ void DefaultBtContext::extractFileEntries(const BDE& infoDict,
} }
length += fileLengthData.i(); length += fileLengthData.i();
const BDE& pathList = fileDict[BtContext::C_PATH]; std::string pathKey;
if(fileDict.containsKey(BtContext::C_PATH_UTF8)) {
pathKey = BtContext::C_PATH_UTF8;
} else {
pathKey = BtContext::C_PATH;
}
const BDE& pathList = fileDict[pathKey];
if(!pathList.isList() || pathList.empty()) { if(!pathList.isList() || pathList.empty()) {
throw DL_ABORT_EX("Path is empty."); throw DL_ABORT_EX("Path is empty.");
} }

View File

@ -46,6 +46,7 @@ class DefaultBtContextTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testGetActualBasePath); CPPUNIT_TEST(testGetActualBasePath);
CPPUNIT_TEST(testSetFileFilter_single); CPPUNIT_TEST(testSetFileFilter_single);
CPPUNIT_TEST(testSetFileFilter_multi); CPPUNIT_TEST(testSetFileFilter_multi);
CPPUNIT_TEST(testUTF8Torrent);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
public: public:
void setUp() { void setUp() {
@ -80,6 +81,7 @@ public:
void testGetActualBasePath(); void testGetActualBasePath();
void testSetFileFilter_single(); void testSetFileFilter_single();
void testSetFileFilter_multi(); void testSetFileFilter_multi();
void testUTF8Torrent();
}; };
@ -596,4 +598,13 @@ void DefaultBtContextTest::testSetFileFilter_multi()
CPPUNIT_ASSERT(ctx.getFileEntries()[1]->isRequested()); CPPUNIT_ASSERT(ctx.getFileEntries()[1]->isRequested());
} }
void DefaultBtContextTest::testUTF8Torrent()
{
DefaultBtContext ctx;
ctx.load("utf8.torrent");
CPPUNIT_ASSERT_EQUAL(std::string("name in utf-8"), ctx.getName());
CPPUNIT_ASSERT_EQUAL(std::string("./name in utf-8/path in utf-8"),
ctx.getFileEntries()[0]->getPath());
}
} // namespace aria2 } // namespace aria2

1
test/utf8.torrent Normal file
View File

@ -0,0 +1 @@
d8:announce36:http://aria.rednoah.com/announce.php13:announce-listll16:http://tracker1 el15:http://tracker2el15:http://tracker3ee7:privatei1e7:comment17:REDNOAH.COM RULES13:creation datei1123456789e4:infod5:filesld6:lengthi284e4:pathl5:aria23:src6:aria2ce10:path.utf-8l13:path in utf-8eed6:lengthi100e4:pathl19:aria2-0.2.2.tar.bz2eee4:name10:aria2-test10:name.utf-813:name in utf-812:piece lengthi128e6:pieces60:AAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCee