2007-10-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

* src/Request.cc (parseUrl): Removed unnecessary slashes around 
dir.
pull/1/head
Tatsuhiro Tsujikawa 2007-10-14 16:29:05 +00:00
parent e5454000a6
commit c0b467273c
3 changed files with 42 additions and 2 deletions

View File

@ -1,3 +1,7 @@
2007-10-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/Request.cc (parseUrl): Removed unnecessary slashes around dir.
2007-10-14 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/MultiUrlRequestInfo.h: Updated the message shown when program

View File

@ -77,7 +77,6 @@ bool Request::parseUrl(const string& url) {
} else {
tempUrl = url;
}
currentUrl = tempUrl;
string query;
host = "";
@ -122,7 +121,16 @@ bool Request::parseUrl(const string& url) {
dir = "/";
direp = hep;
} else {
dir = tempUrl.substr(hep, direp-hep);
string rawDir = tempUrl.substr(hep, direp-hep);
string::size_type p = rawDir.find_first_not_of("/");
if(p != string::npos) {
rawDir.erase(0, p-1);
}
p = rawDir.find_last_not_of("/");
if(p != string::npos) {
rawDir.erase(p+1);
}
dir = rawDir;
}
if(tempUrl.size() > direp+1) {
file = tempUrl.substr(direp+1);

View File

@ -21,6 +21,8 @@ class RequestTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testSetUrl12);
CPPUNIT_TEST(testSetUrl13);
CPPUNIT_TEST(testSetUrl14);
CPPUNIT_TEST(testSetUrl15);
CPPUNIT_TEST(testSetUrl16);
CPPUNIT_TEST(testRedirectUrl);
CPPUNIT_TEST(testRedirectUrl2);
CPPUNIT_TEST(testResetUrl);
@ -48,6 +50,8 @@ public:
void testSetUrl12();
void testSetUrl13();
void testSetUrl14();
void testSetUrl15();
void testSetUrl16();
void testRedirectUrl();
void testRedirectUrl2();
void testResetUrl();
@ -217,6 +221,30 @@ void RequestTest::testSetUrl14() {
CPPUNIT_ASSERT_EQUAL(string("abc?query"), req.getFile());
}
void RequestTest::testSetUrl15()
{
Request req;
// 2 slashes after host name and dir
bool v = req.setUrl("http://host//dir1/dir2//file");
CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
CPPUNIT_ASSERT_EQUAL(string("host"), req.getHost());
CPPUNIT_ASSERT_EQUAL(string("/dir1/dir2"), req.getDir());
CPPUNIT_ASSERT_EQUAL(string("file"), req.getFile());
}
void RequestTest::testSetUrl16()
{
Request req;
// 2 slashes before file
bool v = req.setUrl("http://host//file");
CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(string("http"), req.getProtocol());
CPPUNIT_ASSERT_EQUAL(string("host"), req.getHost());
CPPUNIT_ASSERT_EQUAL(string("/"), req.getDir());
CPPUNIT_ASSERT_EQUAL(string("file"), req.getFile());
}
void RequestTest::testRedirectUrl() {
Request req;
bool v = req.setUrl("http://aria.rednoah.com:8080/aria2/index.html");