diff --git a/Server/RequestHandler.cpp b/Server/RequestHandler.cpp index 11a82798c15..ba6d20629f2 100644 --- a/Server/RequestHandler.cpp +++ b/Server/RequestHandler.cpp @@ -45,7 +45,8 @@ RequestHandler::RequestHandler() : routing_machine(NULL) { } void RequestHandler::handle_request(const http::Request& req, http::Reply& rep){ //parse command try { - std::string request(req.uri); + std::string request; + URIDecode(req.uri, request); time_t ltime; struct tm *Tm; @@ -61,7 +62,7 @@ void RequestHandler::handle_request(const http::Request& req, http::Reply& rep){ Tm->tm_min << ":" << (Tm->tm_sec < 10 ? "0" : "" ) << Tm->tm_sec << " " << req.endpoint.to_string() << " " << req.referrer << ( 0 == req.referrer.length() ? "- " :" ") << - req.agent << ( 0 == req.agent.length() ? "- " :" ") << req.uri; + req.agent << ( 0 == req.agent.length() ? "- " :" ") << request; RouteParameters route_parameters; APIGrammarParser api_parser(&route_parameters); diff --git a/Util/StringUtil.h b/Util/StringUtil.h index 8a86df109b2..8ef2a15295f 100644 --- a/Util/StringUtil.h +++ b/Util/StringUtil.h @@ -36,6 +36,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #include // precision: position after decimal point @@ -177,6 +178,36 @@ inline std::string HTMLDeEntitize( std::string & result) { return result; } +inline std::size_t URIDecode(const std::string & input, std::string & output) { + std::string::const_iterator src_iter = input.begin(); + output.resize(input.size()+1); + std::size_t decoded_length = 0; + for( decoded_length = 0; src_iter != input.end(); ++decoded_length ) { + if( + src_iter[0] == '%' && + src_iter[1] && + src_iter[2] && + isxdigit(src_iter[1]) && + isxdigit(src_iter[2]) + ) { + std::string::value_type a = src_iter[1]; + std::string::value_type b = src_iter[2]; + a -= src_iter[1] < 58 ? 48 : src_iter[1] < 71 ? 55 : 87; + b -= src_iter[2] < 58 ? 48 : src_iter[2] < 71 ? 55 : 87; + output[decoded_length] = 16 * a + b; + src_iter += 3; + continue; + } + output[decoded_length] = *src_iter++; + } + output.resize(decoded_length); + return decoded_length; +} + +inline std::size_t URIDecodeInPlace(std::string & URI) { + return URIDecode(URI, URI); +} + inline bool StringStartsWith( const std::string & input, const std::string & prefix