From 460cccddf988d13eac46dd020bd8a88cc7f242f8 Mon Sep 17 00:00:00 2001 From: Aleksandar Fabijanic Date: Sat, 8 Jun 2013 20:34:46 -0500 Subject: [PATCH] HTMLForm does not read URL parameters on POST or PUT - fixed GH #175: HTMLForm does not read URL parameters on POST or PUT --- CHANGELOG | 4 +++- Net/src/HTMLForm.cpp | 15 +++++++++------ Net/testsuite/src/HTMLFormTest.cpp | 28 ++++++++++++++++++++++------ Net/testsuite/src/HTMLFormTest.h | 5 +++-- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index abeb430bb..091d3377c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,7 +7,7 @@ Release 1.5.2 (2013-06-xx) - added VoidEvent (Arturo Castro) - fixed GH #80: NumberFormatter::append broken - fixed GH #93: ParallelSocketAcceptor virtual functions -- small object optimization for IPAddress, SocketAddress, Any and Dynamic::Var +- optional small object optimization for IPAddress, SocketAddress, Any and Dynamic::Var - SQLite events (insert, update, delete, commit, rollback) handlers - merged GH #91: Improve SQLite multi-threaded use (Rangel Reale) - merged GH #86: Invalid pointers to vector internals (Adrian Imboden) @@ -79,6 +79,8 @@ Release 1.5.2 (2013-06-xx) - fixed GH #99: JSON::Query an JSON::Object - limited allowed types for JSON::Query to Object, Array, Object::Ptr, Array::Ptr and empty +- fixed GH #175: HTMLForm does not read URL parameters on POST or PUT + Release 1.5.1 (2013-01-11) ========================== diff --git a/Net/src/HTMLForm.cpp b/Net/src/HTMLForm.cpp index bd3683ef1..7b5d19d1c 100644 --- a/Net/src/HTMLForm.cpp +++ b/Net/src/HTMLForm.cpp @@ -129,6 +129,15 @@ void HTMLForm::addPart(const std::string& name, PartSource* pSource) void HTMLForm::load(const HTTPRequest& request, std::istream& requestBody, PartHandler& handler) { clear(); + + URI uri(request.getURI()); + const std::string& query = uri.getRawQuery(); + if (!query.empty()) + { + std::istringstream istr(query); + readUrl(istr); + } + if (request.getMethod() == HTTPRequest::HTTP_POST || request.getMethod() == HTTPRequest::HTTP_PUT) { std::string mediaType; @@ -145,12 +154,6 @@ void HTMLForm::load(const HTTPRequest& request, std::istream& requestBody, PartH readUrl(requestBody); } } - else - { - URI uri(request.getURI()); - std::istringstream istr(uri.getRawQuery()); - readUrl(istr); - } } diff --git a/Net/testsuite/src/HTMLFormTest.cpp b/Net/testsuite/src/HTMLFormTest.cpp index c100ea197..0ba60ad31 100644 --- a/Net/testsuite/src/HTMLFormTest.cpp +++ b/Net/testsuite/src/HTMLFormTest.cpp @@ -170,7 +170,7 @@ void HTMLFormTest::testWriteMultipart() } -void HTMLFormTest::testReadUrl1() +void HTMLFormTest::testReadUrlGET() { HTTPRequest req("GET", "/form.cgi?field1=value1&field2=value%202&field3=value%3D3&field4=value%264"); HTMLForm form(req); @@ -182,12 +182,27 @@ void HTMLFormTest::testReadUrl1() } -void HTMLFormTest::testReadUrl2() +void HTMLFormTest::testReadUrlPOST() { - HTTPRequest req("POST", "/form.cgi"); + HTTPRequest req("POST", "/form.cgi?field0=value0"); std::istringstream istr("field1=value1&field2=value%202&field3=value%3D3&field4=value%264"); HTMLForm form(req, istr); - assert (form.size() == 4); + assert (form.size() == 5); + assert (form["field0"] == "value0"); + assert (form["field1"] == "value1"); + assert (form["field2"] == "value 2"); + assert (form["field3"] == "value=3"); + assert (form["field4"] == "value&4"); +} + + +void HTMLFormTest::testReadUrlPUT() +{ + HTTPRequest req("PUT", "/form.cgi?field0=value0"); + std::istringstream istr("field1=value1&field2=value%202&field3=value%3D3&field4=value%264"); + HTMLForm form(req, istr); + assert (form.size() == 5); + assert (form["field0"] == "value0"); assert (form["field1"] == "value1"); assert (form["field2"] == "value 2"); assert (form["field3"] == "value=3"); @@ -360,8 +375,9 @@ CppUnit::Test* HTMLFormTest::suite() CppUnit_addTest(pSuite, HTMLFormTest, testWriteUrl); CppUnit_addTest(pSuite, HTMLFormTest, testWriteMultipart); - CppUnit_addTest(pSuite, HTMLFormTest, testReadUrl1); - CppUnit_addTest(pSuite, HTMLFormTest, testReadUrl2); + CppUnit_addTest(pSuite, HTMLFormTest, testReadUrlGET); + CppUnit_addTest(pSuite, HTMLFormTest, testReadUrlPOST); + CppUnit_addTest(pSuite, HTMLFormTest, testReadUrlPUT); CppUnit_addTest(pSuite, HTMLFormTest, testReadMultipart); CppUnit_addTest(pSuite, HTMLFormTest, testSubmit1); CppUnit_addTest(pSuite, HTMLFormTest, testSubmit2); diff --git a/Net/testsuite/src/HTMLFormTest.h b/Net/testsuite/src/HTMLFormTest.h index 19af61257..bf53080b0 100644 --- a/Net/testsuite/src/HTMLFormTest.h +++ b/Net/testsuite/src/HTMLFormTest.h @@ -48,8 +48,9 @@ public: void testWriteUrl(); void testWriteMultipart(); - void testReadUrl1(); - void testReadUrl2(); + void testReadUrlGET(); + void testReadUrlPOST(); + void testReadUrlPUT(); void testReadMultipart(); void testSubmit1(); void testSubmit2();