2008-10-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Fixed the bug that last character in URI is not encoded.
	* src/Request.cc
	* test/RequestTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-10-08 16:06:27 +00:00
parent 22af8b4b22
commit 1605b39a10
3 changed files with 10 additions and 6 deletions

View File

@ -1,3 +1,9 @@
2008-10-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed the bug that last character in URI is not encoded.
* src/Request.cc
* test/RequestTest.cc
2008-10-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Fixed the bug that referer header field contains fragment.

View File

@ -96,10 +96,8 @@ static std::string urlencode(const std::string& src)
if(src.empty()) {
return result;
}
size_t lastIndex = src.size()-1;
result += " ";
size_t index = lastIndex;
while(index-- > 0) {
for(int index = src.size()-1; index >= 0; --index) {
const unsigned char c = result[index];
// '/' is not urlencoded because src is expected to be a path.
if(Util::shouldUrlencode(c)) {

View File

@ -264,15 +264,15 @@ void RequestTest::testSetUrl16()
void RequestTest::testSetUrl17()
{
Request req;
bool v = req.setUrl("http://host:80/file<with%2 %20space/file with space;param?a=/?");
bool v = req.setUrl("http://host:80/file<with%2 %20space/file with space;param%?a=/?");
CPPUNIT_ASSERT(v);
CPPUNIT_ASSERT_EQUAL(std::string("http"), req.getProtocol());
CPPUNIT_ASSERT_EQUAL(std::string("host"), req.getHost());
CPPUNIT_ASSERT_EQUAL(std::string("/file%3cwith%252%20%20space"), req.getDir());
CPPUNIT_ASSERT_EQUAL(std::string("file%20with%20space;param"), req.getFile());
CPPUNIT_ASSERT_EQUAL(std::string("file%20with%20space;param%25"), req.getFile());
CPPUNIT_ASSERT_EQUAL(std::string("?a=/?"), req.getQuery());
CPPUNIT_ASSERT_EQUAL(std::string("http://host:80/file%3cwith%252%20%20space"
"/file%20with%20space;param?a=/?"),
"/file%20with%20space;param%25?a=/?"),
req.getCurrentUrl());
CPPUNIT_ASSERT_EQUAL(req.getCurrentUrl(), req.getUrl());
}