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

`last_request.querystring` converting escaped pluses to spaces #240

Open
twolfson opened this issue Apr 17, 2015 · 7 comments
Open

`last_request.querystring` converting escaped pluses to spaces #240

twolfson opened this issue Apr 17, 2015 · 7 comments

Comments

@twolfson
Copy link

@twolfson twolfson commented Apr 17, 2015

We are using HTTPretty for testing requests that carry along email addresses. Sometimes email addresses have +'s in them which are escaped to %2B. When they are being reversed for assertion in HTTPretty, it seems to be unescaping too many times in querystring (leading to a ).

# Open request with escaped `+` in it
urllib2.urlopen('http://test.domain/?hello=world&email=todd%2Btest%40underdog.io')

# Look at request received by httpretty
last_request = httpretty.last_request()
print last_request.path  # /?hello=world&email=todd%2Btest%40underdog.io
print last_request.querystring  # {u'hello': [u'world'], u'email': [u'todd test@underdog.io']}

I have created a proof of concept to reproduce the issue:

https://gist.github.com/twolfson/9950fbeb31fc4f3ac33f

I will be attempting to follow up with a PR to remedy the issue fully.

@twolfson
Copy link
Author

@twolfson twolfson commented Apr 17, 2015

I have found the root of the problem. It looks like our second phase of parsing is re-unescaping and replacing pluses with spaces:

https://github.com/gabrielfalcao/HTTPretty/blob/0.8.3/httpretty/core.py#L192-L193

https://hg.python.org/cpython/file/2.7/Lib/urlparse.py#l425

https://hg.python.org/cpython/file/2.7/Lib/urlparse.py#l336

@twolfson
Copy link
Author

@twolfson twolfson commented Apr 17, 2015

I have run out of time and will no longer be submitting a PR. I got as far as swapping unquote for unquote_plus but am having trouble with determining how to deal with the querystring parsing issue further.

https://github.com/gabrielfalcao/HTTPretty/blob/0.8.3/httpretty/compat.py#L64-L69

@ishtiaque-khan
Copy link

@ishtiaque-khan ishtiaque-khan commented Jul 14, 2018

Hey, was any solution found for this? I am having the same problem.

@twolfson
Copy link
Author

@twolfson twolfson commented Jul 14, 2018

I no longer have access to the repo but I'm guessing we either:

  • Worked around it in tests
  • Forked, partially patched, and pointed to fork in repo
@ishtiaque-khan
Copy link

@ishtiaque-khan ishtiaque-khan commented Jul 15, 2018

@twolfson I am guessing the fix is not yet merged. Any thoughts on the workaround for this?

@twolfson
Copy link
Author

@twolfson twolfson commented Jul 15, 2018

No PR fix was submitted due to running out of time. Sorry, I should have clarified by no longer having access to the repo, I meant I don't recall the workaround and can't look it up due to not having access to the repo =/

The guesses above are the best I've got

@gabrielfalcao
Copy link
Owner

@gabrielfalcao gabrielfalcao commented Mar 11, 2020

triaging this ticket, will work on it after next release 1.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.