-
-
Notifications
You must be signed in to change notification settings - Fork 869
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
Percent sign not encoded when present in query params value #2670
Comments
This is related to the changes here: #2543 |
Also for forward-slashes #2661 |
Okay, so let's frame the intended behaviour through public API, rather than private API... def test_param_requires_encoding():
url = httpx.URL('http://webservice', params={"u": "with spaces"})
assert str(url) == 'http://webservice?u=with%20spaces'
def test_param_does_not_require_encoding():
url = httpx.URL('http://webservice', params={"u": "with%20spaces"})
assert str(url) == 'http://webservice?u=with%20spaces'
def test_param_with_existing_escape_requires_encoding():
url = httpx.URL('http://webservice', params={"u": "http://example.com?q=foo%2Fa"})
assert str(url) == 'http://webservice?u=http%3A//example.com%3Fq%3Dfoo%252Fa' The final test here is the one which @rslinckx demonstrates as breaking. This is because our existing behaviour will percent-escape only when required, and won't escape already-valid percent encoded sequences. However this clearly isn't desirable. What we actually want is percent-escape only when required, and if we do apply escaping, then we should encode any existing '%' characters, even if they're part of a valid escape sequence. |
If understand correctly, the new code still leaves query parameters which look like already percent-escapes as-is? |
+1 for @dlange-hima I belive that With current solution it's actually impossible to send |
Has anyone tried this with the Twitter API, i.e. forward slash issues? #2661 |
So even if I handle the %2F for calling Twitter myself, it still won't work since now the % obviously gets encoded as well. |
Since httpx 0.24 the behavior regarding query params changed, and possibly contains a bug.
Use case: passing a pre-signed storage url to some webservice which then downloads the file.
The presigned url will contain some percent-escaped sequences.
With the new httpx 0.24, when something like
client.get('http://webservice', params={"u": "http://example.com?q=foo%2Fa"})
is called, the query params are handed to httpx._urls.urlencode:The resulting query string still has %2F in it, which should have been percent encoded as %252F
Here is the same thing using python urllib.parse (which was used pre-0.24)
Here the resulting query string is correctly encoded.
Another way to look at it is as follows:
The text was updated successfully, but these errors were encountered: