8000 Fix 1.3 compat issue. Closes #780 · encode/django-rest-framework@3f91379 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3f91379

Browse files
committed
Fix 1.3 compat issue. Closes #780
1 parent c2280e3 commit 3f91379

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

rest_framework/compat.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,19 +400,23 @@ def parse_datetime(value):
400400
try:
401401
from django.utils.html import smart_urlquote
402402
except ImportError:
403+
import re
404+
from django.utils.encoding import smart_str
403405
try:
404406
from urllib.parse import quote, urlsplit, urlunsplit
405407
except ImportError: # Python 2
406408
from urllib import quote
407409
from urlparse import urlsplit, urlunsplit
408410

411+
unquoted_percents_re = re.compile(r'%(?![0-9A-Fa-f]{2})')
412+
409413
def smart_urlquote(url):
410414
"Quotes a URL if it isn't already quoted."
411415
# Handle IDN before quoting.
412416
scheme, netloc, path, query, fragment = urlsplit(url)
413417
try:
414-
netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE
415-
except UnicodeError: # invalid domain part
418+
netloc = netloc.encode('idna').decode('ascii') # IDN -> ACE
419+
except UnicodeError: # invalid domain part
416420
pass
417421
else:
418422
url = urlunsplit((scheme, netloc, path, query, fragment))
@@ -421,7 +425,7 @@ def smart_urlquote(url):
421425
# contains a % not followed by two hexadecimal digits. See #9655.
422426
if '%' not in url or unquoted_percents_re.search(url):
423427
# See http://bugs.python.org/issue2637
424-
url = quote(force_bytes(url), safe=b'!*\'();:@&=+$,/?#[]~')
428+
url = quote(smart_str(url), safe=b'!*\'();:@&=+$,/?#[]~')
425429

426430
return force_text(url)
427431

0 commit comments

Comments
 (0)
0