2010-03-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

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
pull/1/head
Tatsuhiro Tsujikawa 2010-03-07 14:29:40 +00:00
parent 10b52bd9ac
commit 41b7b9428f
9 changed files with 35 additions and 22 deletions

View File

@ -1,3 +1,15 @@
2010-03-07 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
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 <t-tujikawa@users.sourceforge.net>
urlencode -> percentEncode,

View File

@ -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);

View File

@ -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)) {

View File

@ -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 {

View File

@ -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;
}
}

View File

@ -53,7 +53,7 @@ BDE parse(const std::string& magnet)
eoi = queries.end(); i != eoi; ++i) {
std::pair<std::string, std::string> 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 {

View File

@ -326,7 +326,7 @@ std::string torrentPercentEncode(const std::string& target)
(reinterpret_cast<const unsigned char*>(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*=...
}

View File

@ -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);

View File

@ -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()