This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: urllib.parse.unquote_to_bytes: needs "escape plus" option
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Henry Zhu, andrew-g, lys.nikolaou, orsenthil
Priority: normal Keywords: patch

Created on 2018-10-29 03:55 by Henry Zhu, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 12368 open andrew-g, 2019-03-16 10:26
Messages (3)
msg328786 - (view) Author: Henry Zhu (Henry Zhu) * Date: 2018-10-29 03:55
`urllib.parse.unquote_to_bytes` should have an "escape plus" option, just like `urllib.parse.unquote_plus` does. 

It's very necessary in some cases:

```
# Say I have a url string: 'a+%2b%c0'. 
# In Python2, I can parse it into b'a +\xc0' with urllib.unquote_plus.
# Note that the first "+" was escaped into space, and the second "+" was decoded from "%2b".
# But in Python3, this just can't be done, either with urllib.parse.unquote, urllib.par.unquote_plus or urllib.parse.unquote_to_bytes.
# This is the example:

>>> from urllib import parse
>>> s = 'a+%2b%c0'
>>> parse.unquote(s)
'a++�'
>>> parse.unquote_plus(s)
'a +�'
>>> parse.unquote_to_bytes(s)
b'a++\xc0'
```

PS: the character "�" should be "À", but it can't be shown in command line.

The result of `urllib.parse.unquote_to_bytes` is almost what I want, except that it doesn't escape the first "+" into space.
msg337011 - (view) Author: Lysandros Nikolaou (lys.nikolaou) * (Python committer) Date: 2019-03-02 13:46
This issue still stands. The output of all three methods is exactly the same as it was when the original question was posted. Would it maybe make sense to add a flag to the unquote_to_bytes method to parse the 'plus' symbol as a space? Or maybe create a new method(i.e. unquote_to_bytes_plus)?
msg340480 - (view) Author: (andrew-g) * Date: 2019-04-18 10:02
pinging the issue to try get the PR reviewed
History
Date User Action Args
2022-04-11 14:59:07adminsetgithub: 79281
2019-04-18 10:02:42andrew-gsetnosy: + andrew-g
messages: + msg340480
2019-03-16 10:26:57andrew-gsetkeywords: + patch
stage: patch review
pull_requests: + pull_request12331
2019-03-02 14:58:35SilentGhostsetnosy: + orsenthil

versions: + Python 3.8, - Python 3.5, Python 3.6, Python 3.7
2019-03-02 13:46:44lys.nikolaousetnosy: + lys.nikolaou
messages: + msg337011
2018-10-29 03:55:54Henry Zhucreate