mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-01 17:25:03 +02:00
fix(URI): Decoding URI query parameters ( ::getQueryParameters) incompatible with Spring 5 #2619
This commit is contained in:
parent
4938185ff0
commit
6dc79c05f9
@ -220,7 +220,7 @@ public:
|
||||
///
|
||||
/// The given query string must be properly percent-encoded.
|
||||
|
||||
QueryParameters getQueryParameters() const;
|
||||
QueryParameters getQueryParameters(bool plusIsSpace = true) const;
|
||||
/// Returns the decoded query string parameters as a vector
|
||||
/// of name-value pairs.
|
||||
|
||||
|
@ -370,7 +370,7 @@ std::string URI::getQuery() const
|
||||
}
|
||||
|
||||
|
||||
URI::QueryParameters URI::getQueryParameters() const
|
||||
URI::QueryParameters URI::getQueryParameters(bool plusIsSpace) const
|
||||
{
|
||||
QueryParameters result;
|
||||
std::string::const_iterator it(_query.begin());
|
||||
@ -381,7 +381,7 @@ URI::QueryParameters URI::getQueryParameters() const
|
||||
std::string value;
|
||||
while (it != end && *it != '=' && *it != '&')
|
||||
{
|
||||
if (*it == '+')
|
||||
if (plusIsSpace && (*it == '+'))
|
||||
name += ' ';
|
||||
else
|
||||
name += *it;
|
||||
@ -392,7 +392,7 @@ URI::QueryParameters URI::getQueryParameters() const
|
||||
++it;
|
||||
while (it != end && *it != '&')
|
||||
{
|
||||
if (*it == '+')
|
||||
if (plusIsSpace && (*it == '+'))
|
||||
value += ' ';
|
||||
else
|
||||
value += *it;
|
||||
|
@ -858,6 +858,40 @@ void URITest::testQueryParameters()
|
||||
}
|
||||
|
||||
|
||||
void URITest::testQueryParametersPlus()
|
||||
{
|
||||
Poco::URI uri("http://google.com/search?q=hello+world&client=safari");
|
||||
URI::QueryParameters params = uri.getQueryParameters(false);
|
||||
assertTrue (params.size() == 2);
|
||||
assertTrue (params[0].first == "q");
|
||||
assertTrue (params[0].second == "hello+world");
|
||||
assertTrue (params[1].first == "client");
|
||||
assertTrue (params[1].second == "safari");
|
||||
|
||||
uri.setQueryParameters(params);
|
||||
assertTrue (uri.toString() == "http://google.com/search?q=hello%2Bworld&client=safari");
|
||||
|
||||
uri = "http://google.com/search?q=&client&";
|
||||
params = uri.getQueryParameters();
|
||||
assertTrue (params.size() == 2);
|
||||
assertTrue (params[0].first == "q");
|
||||
assertTrue (params[0].second == "");
|
||||
assertTrue (params[1].first == "client");
|
||||
assertTrue (params[1].second == "");
|
||||
|
||||
uri.setQueryParameters(params);
|
||||
assertTrue (uri.toString() == "http://google.com/search?q=&client=");
|
||||
|
||||
params[0].second = "foo/bar?";
|
||||
uri.setQueryParameters(params);
|
||||
assertTrue (uri.toString() == "http://google.com/search?q=foo%2Fbar%3F&client=");
|
||||
|
||||
params[0].second = "foo&bar";
|
||||
uri.setQueryParameters(params);
|
||||
assertTrue (uri.toString() == "http://google.com/search?q=foo%26bar&client=");
|
||||
}
|
||||
|
||||
|
||||
void URITest::setUp()
|
||||
{
|
||||
}
|
||||
@ -883,6 +917,7 @@ CppUnit::Test* URITest::suite()
|
||||
CppUnit_addTest(pSuite, URITest, testOther);
|
||||
CppUnit_addTest(pSuite, URITest, testFromPath);
|
||||
CppUnit_addTest(pSuite, URITest, testQueryParameters);
|
||||
CppUnit_addTest(pSuite, URITest, testQueryParametersPlus);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
void testOther();
|
||||
void testFromPath();
|
||||
void testQueryParameters();
|
||||
void testQueryParametersPlus();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
Loading…
x
Reference in New Issue
Block a user