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

Unquote paths #188

Merged
merged 9 commits into from
Oct 16, 2020
Merged

Unquote paths #188

merged 9 commits into from
Oct 16, 2020

Conversation

Cox65
Copy link
Contributor

@Cox65 Cox65 commented Oct 14, 2020

It seems that there is an issue with path parameters which are not decoded before being passed to the WSGI application.
Looks like it is a common discussion when implementing WSGI adapter: benoitc/gunicorn#1211

In my case I was receiving my path parameter still encoded in my Flask application.

Based on my researches, here is the fix.

@Cox65 Cox65 changed the title Bug/encoded path parameters Path parameters decoding for PATH_INFO Oct 14, 2020
Copy link
Owner

@adamchainz adamchainz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! It looks like a rare gnarly issue.

Have you got an example path that you could add into some tests to prevent regressions?

Also, wouldn't unquote(_, encoding="iso-8859-1") work just as well, and avoid the trip through bytes and back?

@Cox65
Copy link
Contributor Author

Cox65 commented Oct 16, 2020

I made changes and added tests.
I introduced an optional parameter to the make_lambda_handler to be able to disable path unquoting as it seems that for some WSGI app it is not necessary. This way it can manage both behaviours.

@adamchainz
Copy link
Owner

I introduced an optional parameter to the make_lambda_handler to be able to disable path unquoting as it seems that for some WSGI app it is not necessary.

When you say "not necessary", you mean it isn't strictly required because no URL path needs it? If so, I wouldn't want to make this a switch. Other users won't know what this means. We should just do the right thing every time. For example, gunicorn always decodes the path correctly...

@Cox65
Copy link
Contributor Author

Cox65 commented Oct 16, 2020

As I was not able to find a strict answer so I prefered to add this option but you are right, in this case, we need to follow PEP 3333 specifications.
As described here : benoitc/gunicorn#1211 (comment)
I remove this part and commit.

@adamchainz adamchainz changed the title Path parameters decoding for PATH_INFO Correctly unquote paths Oct 16, 2020
@adamchainz adamchainz changed the title Correctly unquote paths Unquote paths Oct 16, 2020
@adamchainz adamchainz merged commit 75391ae into adamchainz:master Oct 16, 2020
@adamchainz
Copy link
Owner

Thanks! Released in version 2.9.2.

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

Successfully merging this pull request may close these issues.

2 participants