URI-encoding when redirecting legacy URLs to /content

Testing of this functionality revealed that the query part containing +
symbols (as replacement for spaces in the parameter values) isn't
forwarded properly as the + symbols are URI-encoded (this is a bug on
the part of the `RequestContext::get_query()` the result of which
already contains URI-encoded +'s).
This commit is contained in:
Veloman Yunkan 2023-02-08 17:31:59 +01:00
parent 58bb8b9843
commit a807ce27f1
2 changed files with 14 additions and 1 deletions

View File

@ -607,7 +607,7 @@ std::unique_ptr<Response> InternalServer::handle_request(const RequestContext& r
if (isEndpointUrl(url, "catch")) if (isEndpointUrl(url, "catch"))
return handle_catch(request); return handle_catch(request);
std::string contentUrl = m_root + "/content" + url; std::string contentUrl = urlEncode(m_root + "/content" + url);
const std::string query = request.get_query(); const std::string query = request.get_query();
if ( ! query.empty() ) if ( ! query.empty() )
contentUrl += "?" + query; contentUrl += "?" + query;

View File

@ -1310,6 +1310,19 @@ TEST_F(ServerTest, NonEndpointUrlsAreRedirectedToContentUrls)
// Make sure that the query is preserved in the redirect URL // Make sure that the query is preserved in the redirect URL
"/does?P=NP" "/does?P=NP"
// Make sure that reserved URI encoded symbols stay URI encoded
"/C%23", // # --> /C#
"/100%25_guarantee", // % --> /100%_guarantee
"/AT%26T", // & --> /AT&T
"/Quo_vadis%3F", // ? --> /Quo_vadis?
"/1%2B1%3D2", // +,= --> 1+1=2
// Make sure that URI-encoded query stays URI-encoded
"/encode?string=%23%25%26%2B%3D%3F",
// Bug: the + symbol (that replaces space) in the query gets URI-encoded
//"/route?from=current+location&to=girlfriend%238",
}; };
for ( const std::string& p : paths ) for ( const std::string& p : paths )