Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

whitespaces encode to %20 #16

Open
zys864 opened this issue Mar 3, 2022 · 5 comments
Open

whitespaces encode to %20 #16

zys864 opened this issue Mar 3, 2022 · 5 comments

Comments

@zys864
Copy link

zys864 commented Mar 3, 2022

I think (whitespace) should be encoded as %20,which will works on URL that contains whitespaces.
I test on julienschmidt/httprouter,the http://127.0.0.1:3000/hell o/name works, but matchit not.
Or there are some misusage for me.

@ibraheemdev
Copy link
Owner

As discussed privately, I don't think percent-decoding is something matchit should handle.

@mladedav
Copy link

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.

@ibraheemdev
Copy link
Owner

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.

@mladedav
Copy link

mladedav commented Mar 21, 2024

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?

@ibraheemdev
Copy link
Owner

@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.

@ibraheemdev ibraheemdev reopened this Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants