From 41b7b9428f590652a6b27b4854e3d978f778bb30 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 7 Mar 2010 14:29:40 +0000 Subject: [PATCH] 2010-03-07 Tatsuhiro Tsujikawa urldecode -> percentDecode * src/FtpConnection.cc * src/FtpNegotiationCommand.cc * src/HttpResponse.cc * src/Request.cc * src/magnet.cc * src/util.cc * src/util.h * test/UtilTest.cc --- ChangeLog | 12 ++++++++++++ src/FtpConnection.cc | 8 ++++---- src/FtpNegotiationCommand.cc | 2 +- src/HttpResponse.cc | 2 +- src/Request.cc | 4 ++-- src/magnet.cc | 2 +- src/util.cc | 7 ++++--- src/util.h | 2 +- test/UtilTest.cc | 18 +++++++++--------- 9 files changed, 35 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6a3026ce..9b5ddc55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2010-03-07 Tatsuhiro Tsujikawa + + urldecode -> percentDecode + * src/FtpConnection.cc + * src/FtpNegotiationCommand.cc + * src/HttpResponse.cc + * src/Request.cc + * src/magnet.cc + * src/util.cc + * src/util.h + * test/UtilTest.cc + 2010-03-07 Tatsuhiro Tsujikawa urlencode -> percentEncode, diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc index fac7554f..f14262ba 100644 --- a/src/FtpConnection.cc +++ b/src/FtpConnection.cc @@ -139,7 +139,7 @@ bool FtpConnection::sendCwd() if(_baseWorkingDir != "/") { request += _baseWorkingDir; } - request += util::urldecode(req->getDir()); + request += util::percentDecode(req->getDir()); request += "\r\n"; logger->info(MSG_SENDING_REQUEST, cuid, request.c_str()); _socketBuffer.pushStr(request); @@ -152,7 +152,7 @@ bool FtpConnection::sendMdtm() { if(_socketBuffer.sendBufferIsEmpty()) { std::string request = "MDTM "; - request += util::urldecode(req->getFile()); + request += util::percentDecode(req->getFile()); request += "\r\n"; logger->info(MSG_SENDING_REQUEST, cuid, request.c_str()); _socketBuffer.pushStr(request); @@ -165,7 +165,7 @@ bool FtpConnection::sendSize() { if(_socketBuffer.sendBufferIsEmpty()) { std::string request = "SIZE "; - request += util::urldecode(req->getFile()); + request += util::percentDecode(req->getFile()); request += "\r\n"; logger->info(MSG_SENDING_REQUEST, cuid, request.c_str()); _socketBuffer.pushStr(request); @@ -245,7 +245,7 @@ bool FtpConnection::sendRetr() { if(_socketBuffer.sendBufferIsEmpty()) { std::string request = "RETR "; - request += util::urldecode(req->getFile()); + request += util::percentDecode(req->getFile()); request += "\r\n"; logger->info(MSG_SENDING_REQUEST, cuid, request.c_str()); _socketBuffer.pushStr(request); diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc index 32f532d8..53c373e0 100644 --- a/src/FtpNegotiationCommand.cc +++ b/src/FtpNegotiationCommand.cc @@ -344,7 +344,7 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength) _fileEntry->setPath (util::applyDir (getDownloadContext()->getDir(), - util::fixTaintedBasename(util::urldecode(req->getFile())))); + util::fixTaintedBasename(util::percentDecode(req->getFile())))); } _requestGroup->preDownloadProcessing(); if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) { diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc index b7a4f413..62910082 100644 --- a/src/HttpResponse.cc +++ b/src/HttpResponse.cc @@ -98,7 +98,7 @@ std::string HttpResponse::determinFilename() const util::getContentDispositionFilename (httpHeader->getFirst(HttpHeader::CONTENT_DISPOSITION)); if(contentDisposition.empty()) { - std::string file = util::urldecode(httpRequest->getFile()); + std::string file = util::percentDecode(httpRequest->getFile()); if(file.empty()) { return "index.html"; } else { diff --git a/src/Request.cc b/src/Request.cc index fa2f650e..9fbba5ab 100644 --- a/src/Request.cc +++ b/src/Request.cc @@ -206,12 +206,12 @@ bool Request::parseUri(const std::string& srcUri) { std::string::const_iterator userLast = authorityFirst; for(; userLast != userInfoLast; ++userLast) { if(*userLast == ':') { - _password = util::urldecode(std::string(userLast+1, userInfoLast)); + _password = util::percentDecode(std::string(userLast+1,userInfoLast)); _hasPassword = true; break; } } - _username = util::urldecode(std::string(authorityFirst, userLast)); + _username = util::percentDecode(std::string(authorityFirst, userLast)); break; } } diff --git a/src/magnet.cc b/src/magnet.cc index 8fb3d6a1..3118bf64 100644 --- a/src/magnet.cc +++ b/src/magnet.cc @@ -53,7 +53,7 @@ BDE parse(const std::string& magnet) eoi = queries.end(); i != eoi; ++i) { std::pair kv; util::split(kv, *i, '='); - std::string value = util::urldecode(kv.second); + std::string value = util::percentDecode(kv.second); if(dict.containsKey(kv.first)) { dict[kv.first] << value; } else { diff --git a/src/util.cc b/src/util.cc index 2481067c..f2f14130 100644 --- a/src/util.cc +++ b/src/util.cc @@ -326,7 +326,7 @@ std::string torrentPercentEncode(const std::string& target) (reinterpret_cast(target.c_str()), target.size()); } -std::string urldecode(const std::string& target) { +std::string percentDecode(const std::string& target) { std::string result; for(std::string::const_iterator itr = target.begin(), eoi = target.end(); itr != eoi; ++itr) { @@ -759,7 +759,7 @@ std::string getContentDispositionFilename(const std::string& header) if(bad) { continue; } - value = trimBasename(urldecode(value)); + value = trimBasename(percentDecode(value)); if(toLower(extValues[0]) == "iso-8859-1") { value = iso8859ToUtf8(value); } @@ -785,7 +785,8 @@ std::string getContentDispositionFilename(const std::string& header) } else { filenameLast = value.end(); } - value = trimBasename(urldecode(std::string(value.begin(), filenameLast))); + value = + trimBasename(percentDecode(std::string(value.begin(), filenameLast))); filename = value; // continue because there is a chance we can find filename*=... } diff --git a/src/util.h b/src/util.h index 7819cb80..1824b609 100644 --- a/src/util.h +++ b/src/util.h @@ -145,7 +145,7 @@ bool inRFC3986ReservedChars(const char c); bool inRFC3986UnreservedChars(const char c); -std::string urldecode(const std::string& target); +std::string percentDecode(const std::string& target); std::string torrentPercentEncode(const unsigned char* target, size_t len); diff --git a/test/UtilTest.cc b/test/UtilTest.cc index b5169fbd..1ac17952 100644 --- a/test/UtilTest.cc +++ b/test/UtilTest.cc @@ -30,7 +30,7 @@ class UtilTest:public CppUnit::TestFixture { CPPUNIT_TEST(testRandomAlpha); CPPUNIT_TEST(testToUpper); CPPUNIT_TEST(testToLower); - CPPUNIT_TEST(testUrldecode); + CPPUNIT_TEST(testPercentDecode); CPPUNIT_TEST(testGetRealSize); CPPUNIT_TEST(testAbbrevSize); CPPUNIT_TEST(testToStream); @@ -81,7 +81,7 @@ public: void testRandomAlpha(); void testToUpper(); void testToLower(); - void testUrldecode(); + void testPercentDecode(); void testGetRealSize(); void testAbbrevSize(); void testToStream(); @@ -416,25 +416,25 @@ void UtilTest::testToLower() { CPPUNIT_ASSERT_EQUAL(upp, util::toLower(src)); } -void UtilTest::testUrldecode() { +void UtilTest::testPercentDecode() { std::string src = "http://aria2.sourceforge.net/aria2%200.7.0%20docs.html"; CPPUNIT_ASSERT_EQUAL(std::string("http://aria2.sourceforge.net/aria2 0.7.0 docs.html"), - util::urldecode(src)); + util::percentDecode(src)); std::string src2 = "aria2+aria2"; - CPPUNIT_ASSERT_EQUAL(std::string("aria2+aria2"), util::urldecode(src2)); + CPPUNIT_ASSERT_EQUAL(std::string("aria2+aria2"), util::percentDecode(src2)); std::string src3 = "%5t%20"; - CPPUNIT_ASSERT_EQUAL(std::string("%5t "), util::urldecode(src3)); + CPPUNIT_ASSERT_EQUAL(std::string("%5t "), util::percentDecode(src3)); std::string src4 = "%"; - CPPUNIT_ASSERT_EQUAL(std::string("%"), util::urldecode(src4)); + CPPUNIT_ASSERT_EQUAL(std::string("%"), util::percentDecode(src4)); std::string src5 = "%3"; - CPPUNIT_ASSERT_EQUAL(std::string("%3"), util::urldecode(src5)); + CPPUNIT_ASSERT_EQUAL(std::string("%3"), util::percentDecode(src5)); std::string src6 = "%2f"; - CPPUNIT_ASSERT_EQUAL(std::string("/"), util::urldecode(src6)); + CPPUNIT_ASSERT_EQUAL(std::string("/"), util::percentDecode(src6)); } void UtilTest::testGetRealSize()