Simple-Web-Server icon indicating copy to clipboard operation
Simple-Web-Server copied to clipboard

Whitespace encoding in route regular expression

Open ydarma opened this issue 9 years ago • 2 comments

Hi,

first thank you for the Simple-Web-Server which is amazing.

If a path contains a whitespace, the \s pattern won't match. For instance :

^/search?q="two\s+words"$

We need to write instead :

^/search?q="two(?:(?:%20)|\s)+words"$

This is a bit annoying...

Thanks, Yves

ydarma avatar Nov 16 '16 13:11 ydarma

re-Hi,

Actually, we have the same problem with all special characters. For instance a [ must be tested as (?:%5B)|\[ ...

ydarma avatar Nov 16 '16 13:11 ydarma

Since parsing of a HTTP path variables is outside of the scope of this project, you would have to implement this yourself. You could use ^/search?(.*)$ as regex and parse the path_match[1] in the resource function.

Personally, I would not use the HTTP path to pass such variables though, since it is limited (essentially only an associate table of strings, strings (no object structure that is)), and use the content (body) in the request instead (and here be able to use a JSON structure for instance). Even though this might go against the HTTP recommendation for especially GET requests.

eidheim avatar Nov 16 '16 16:11 eidheim