Uh oh!
There was an error while loading. Please reload this page.
Always encode forward slashes as %2F in query parameters - #2723
Conversation
Uh oh!
There was an error while loading. Please reload this page.
This is expected to fail tests due to double escaping
lovelydinosaur
commented
Jun 8, 2023
Okay, so we also need to change this... defurlencode(items: typing.List[typing.Tuple[str, str]]) ->str:
# We can use a much simpler version of the stdlib urlencode here because# we don't need to handle a bunch of different typing cases, such as bytes vs str.## https://github.com/python/cpython/blob/b2f7b2ef0b5421e01efb8c7bee2ef95d3bab77eb/Lib/urllib/parse.py#L926## Note that we use '%20' encoding for spaces, and treat '/' as a safe# character. This means our query params have the same escaping as other# characters in the URL path. This is slightly different to `requests`,# but is the behaviour that browsers use.## See https://github.com/encode/httpx/issues/2536 and# https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlencodereturn"&".join([quote(k) +"="+quote(v) fork, vinitems])To not use the default defurlencode(items: typing.List[typing.Tuple[str, str]]) ->str:
# We can use a much simpler version of the stdlib urlencode here because# we don't need to handle a bunch of different typing cases, such as bytes vs str.## Note that we use '%20' encoding for spaces, instead of "+".return"&".join([quote(k, safe="") +"="+quote(v, safe="") fork, vinitems]) |
zanieb
commented
Jun 8, 2023
Thanks for the hint! I'm pretty confused how it manifested that way still :D |
This needs to be reverted, see this comment and #2883. |
zanieb
commented
Oct 7, 2023
Hi @ttys0dev — I appreciate the sentiment but that's not a great way to collaborate with us. We're considering reverting this and the existing discussion is the place to weigh in with details of why this matters to you. |
ttys0dev
commented
Oct 7, 2023
Oh, I had looked for existing open issues and didn't originally find one tracking this issue yet, I hadn't realized this project often puts issues under discussions(I've never really used the discussions feature before) which is a bit different from other projects. |
| # encoding despite it not being a requirement of the spec. | ||
| parsed_query: typing.Optional[str] = ( | ||
| None if query is None else quote(query, safe=SUB_DELIMS + ":/?[]@") | ||
| None if query is None else quote(query, safe=SUB_DELIMS + ":?[]@") |
There was a problem hiding this comment.
This change was unnecessary. The fix was the changes below. We dont need to change an already encoded query to encode slashes. We do need to handle it when passed in as separate parameter.
* Always encode forward slashes as `%2F` in query parameters * Revert inclusion of "%" This is expected to fail tests due to double escaping * Update `urlencode` --------- Co-authored-by: Tom Christie <tom@tomchristie.com>
Summary
Closeshttps://github.com/encode/httpx/issues/2721
Encodes
/as%2Fin query parameters for more robust behavior matching browser implementations. See issue for discussion.Checklist