eidheim / Simple-Web-Server

A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.
MIT License
2.61k stars 751 forks source link

Turning numbers into %xx #184

Closed SethHamilton closed 6 years ago

SethHamilton commented 6 years ago

https://github.com/eidheim/Simple-Web-Server/blob/1552cdc11acf0baedceb1e146824411506fc12d7/utility.hpp#L51

I think line could be:

else if (!((chr >= '0' && chr <= '9') || (chr >= 'A' && chr <= 'Z') || (chr >= 'a' && chr <= 'z') || chr == '-' || chr == '_'))

Basically 0-9, a-z, A-Z and - and _ are all good to go.

eidheim commented 6 years ago

UTF-8 characters of 2 or more bytes should not be percent encoded I think, but they would be included in your expression if I'm not mistaken.

SethHamilton commented 6 years ago

Sorry for the late response. I'm not certain UTF-8 must be encoded, but both your current code and my example don't take this into account. the issue I have with the current code is this that parameters that are simply numeric (and valid) like someparam=123 are being encoded, and that isn't great (reduced readability and overhead).

eidheim commented 6 years ago

Thank you, after some additional reading I modified your expression by adding a couple more characters (according to http://www.ietf.org/rfc/rfc3986.txt), and added more tests. Your issue should now be fixed.

SethHamilton commented 6 years ago

@eidheim thank you kindly.