Open zys864 opened 2 years ago
As discussed privately, I don't think percent-decoding is something matchit
should handle.
Hi @ibraheemdev, do you remember the details of why you decided against this? From what I understand, percent encoding is part of RFC 3986 so I thought it would be in scope but then I found this.
Matchit isn't necessarily http specific, so implicit percent-encoding/decoding could cause unexpected behavior. My understanding was that routes could either be percent encoded before being passed to matchit, or paths decoded before being matched.
From what I understand, percent encoding should be general for all URIs regardless of whether they are http. That said it might apply to some narrower definition of URI used by IETF than is used in the real world.
I think that the complexity with decoding the path before passing it into matching is that slashes may also be encoded but these should not be simply passed to the router. So I think it should be possible to split a path by slashes, then decode each segment without decoding slashes, join it together again and then pass that into matchit. I didn't yet look into if there may be other characters that should also be handled specially.
I feel like this would be something that could be used fairly often. Would it be ok with you to add an option or some kind of wrapper for percent encoding support into matchit or would you rather the users or some 3rd party wrappers handled that?
@mladedav I would be fine with adding a helper function that percent decodes paths excluding a few reserved characters that would affect parsing (/,?). Actix-web takes a similar approach https://github.com/actix/actix-web/blob/master/actix-router/src/quoter.rs.
I think
` (whitespace) should be encoded as
%20,which will works on
URLthat contains whitespaces. I test on
julienschmidt/httprouter,the
http://127.0.0.1:3000/hell o/nameworks, but
matchit` not. Or there are some misusage for me.