diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index bef72d64b..e1017e287 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -607,7 +607,7 @@ std::unique_ptr InternalServer::handle_request(const RequestContext& r if (isEndpointUrl(url, "catch")) 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(); if ( ! query.empty() ) contentUrl += "?" + query; diff --git a/test/server.cpp b/test/server.cpp index 570c6cb55..ce89b45bc 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -1310,6 +1310,19 @@ TEST_F(ServerTest, NonEndpointUrlsAreRedirectedToContentUrls) // Make sure that the query is preserved in the redirect URL "/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 )