From 41df4b5e2801a6bb960dcc27b43af46bf6a7010f Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 26 May 2009 15:28:48 +0000 Subject: [PATCH] 2009-05-27 Tatsuhiro Tsujikawa 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 --- ChangeLog | 10 ++++++++++ src/BtContext.cc | 4 ++++ src/BtContext.h | 4 ++++ src/DefaultBtContext.cc | 16 ++++++++++++++-- test/DefaultBtContextTest.cc | 11 +++++++++++ test/utf8.torrent | 1 + 6 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 test/utf8.torrent diff --git a/ChangeLog b/ChangeLog index 28edfb30..fecfeb69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-05-27 Tatsuhiro Tsujikawa + + 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 Added --xml-rpc-max-request-size option to limit the size of diff --git a/src/BtContext.cc b/src/BtContext.cc index 4d306041..ee6a896a 100644 --- a/src/BtContext.cc +++ b/src/BtContext.cc @@ -38,12 +38,16 @@ namespace aria2 { 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_LENGTH("length"); 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_PIECES("pieces"); diff --git a/src/BtContext.h b/src/BtContext.h index 606707c7..ffe66739 100644 --- a/src/BtContext.h +++ b/src/BtContext.h @@ -90,12 +90,16 @@ public: static const std::string C_NAME; + static const std::string C_NAME_UTF8; + static const std::string C_FILES; static const std::string C_LENGTH; static const std::string C_PATH; + static const std::string C_PATH_UTF8; + static const std::string C_INFO; static const std::string C_PIECES; diff --git a/src/DefaultBtContext.cc b/src/DefaultBtContext.cc index 7b5613aa..8df1aaf1 100644 --- a/src/DefaultBtContext.cc +++ b/src/DefaultBtContext.cc @@ -117,7 +117,13 @@ void DefaultBtContext::extractFileEntries(const BDE& infoDict, const std::deque& urlList) { 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()) { name = nameData.s(); } else { @@ -146,7 +152,13 @@ void DefaultBtContext::extractFileEntries(const BDE& infoDict, } 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()) { throw DL_ABORT_EX("Path is empty."); } diff --git a/test/DefaultBtContextTest.cc b/test/DefaultBtContextTest.cc index 0966d918..10375d13 100644 --- a/test/DefaultBtContextTest.cc +++ b/test/DefaultBtContextTest.cc @@ -46,6 +46,7 @@ class DefaultBtContextTest:public CppUnit::TestFixture { CPPUNIT_TEST(testGetActualBasePath); CPPUNIT_TEST(testSetFileFilter_single); CPPUNIT_TEST(testSetFileFilter_multi); + CPPUNIT_TEST(testUTF8Torrent); CPPUNIT_TEST_SUITE_END(); public: void setUp() { @@ -80,6 +81,7 @@ public: void testGetActualBasePath(); void testSetFileFilter_single(); void testSetFileFilter_multi(); + void testUTF8Torrent(); }; @@ -596,4 +598,13 @@ void DefaultBtContextTest::testSetFileFilter_multi() 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 diff --git a/test/utf8.torrent b/test/utf8.torrent new file mode 100644 index 00000000..6f26f52f --- /dev/null +++ b/test/utf8.torrent @@ -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 \ No newline at end of file