mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Enhance unquote_unreserved to handle all strings
This commit is contained in:
+12
-4
@@ -422,7 +422,15 @@ def unquote_unreserved(uri):
|
||||
"""Un-escape any percent-escape sequences in a URI that are unreserved
|
||||
characters. This leaves all reserved, illegal and non-ASCII bytes encoded.
|
||||
"""
|
||||
parts = uri.split(b'%')
|
||||
# Handle both bytestrings and unicode strings.
|
||||
if isinstance(uri, bytes):
|
||||
splitchar = b'%'
|
||||
base = b''
|
||||
else:
|
||||
splitchar = u'%'
|
||||
base = u''
|
||||
|
||||
parts = uri.split(splitchar)
|
||||
for i in range(1, len(parts)):
|
||||
h = parts[i][0:2]
|
||||
if len(h) == 2 and h.isalnum():
|
||||
@@ -434,10 +442,10 @@ def unquote_unreserved(uri):
|
||||
if c in UNRESERVED_SET:
|
||||
parts[i] = c + parts[i][2:]
|
||||
else:
|
||||
parts[i] = '%' + parts[i]
|
||||
parts[i] = splitchar + parts[i]
|
||||
else:
|
||||
parts[i] = '%' + parts[i]
|
||||
return ''.join(parts)
|
||||
parts[i] = splitchar + parts[i]
|
||||
return base.join(parts)
|
||||
|
||||
|
||||
def requote_uri(uri):
|
||||
|
||||
Reference in New Issue
Block a user