Suppose I have a URI parameter with value, which contains plus signs (+
) and other special chars.
When I execute URI::setQueryParameters
and then URI::getQueryParameters
, the resulted value is not the same as the original one - all special chars are fine, except the plus sign.
Could you, please, advice what is the conventional way to do this?
Workaround: explicitly invoke URI::encode
with reserved
containing plus sign. But this doesn't seem to be right, it really looks like a workaround.
Anyway, if this is the correct way to achieve this, what symbols should I include in reserved
, if I want to avoid such surprises in the future?
Other observations: URI::decode
has a parameter named plusAsSpace
(defaulted to false
), but this does not help. URI::getQueryParameters
replaces +
with (space) before calling
URI::decode
.
Here's a sample code:
const std::string value_with_plus_signs = "value+with+plus+signs";
Poco::URI::QueryParameters out_params;
out_params.push_back(std::make_pair("param", value_with_plus_signs));
Poco::URI uri("path");
uri.setQueryParameters(out_params);
const auto in_params = uri.getQueryParameters();
std::cout << "Expected: '" << value_with_plus_signs << "', received: '"
<< in_params.front().second << "'" << std::endl;
output: Expected: 'value+with+plus+signs', received: 'value with plus signs'
It seems this was fixed in Poco (notice that '+' is added to the symbols that are encoded by default):
https://github.com/pocoproject/poco/issues/1260 https://github.com/pocoproject/poco/commit/c32e683b6c00950ddfce817dfe8f3fc0b6846455
I tested your code with poco 1.7.9p2 and I got the correct results.