diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2018-10-01 18:18:04 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-10-10 14:38:22 -0400 |
| commit | c82893cb8c6b2a4a876965426c5a5bc4590e1583 (patch) | |
| tree | 933e6e97f1dc87bdb2996556e83eeead7537c547 /django/utils/http.py | |
| parent | f3d3338e06d571a529bb2046428eeac8e56bcbf6 (diff) | |
Refs #27795 -- Removed force_bytes() usage from django/utils/http.py.
django.utils.http.urlsafe_base64_encode() now returns a string, not a
bytestring. Since URLs are represented as strings,
urlsafe_base64_encode() should return a string. All uses immediately
decoded the bytestring to a string anyway.
As the inverse operation, urlsafe_base64_decode() accepts a string.
Diffstat (limited to 'django/utils/http.py')
| -rw-r--r-- | django/utils/http.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/django/utils/http.py b/django/utils/http.py index 5a063a9956..db18e57803 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -15,7 +15,6 @@ from urllib.parse import ( from django.core.exceptions import TooManyFieldsSent from django.utils.datastructures import MultiValueDict from django.utils.deprecation import RemovedInDjango30Warning -from django.utils.encoding import force_bytes from django.utils.functional import keep_lazy_text # based on RFC 7232, Appendix C @@ -220,10 +219,10 @@ def int_to_base36(i): def urlsafe_base64_encode(s): """ - Encode a bytestring in base64 for use in URLs. Strip any trailing equal - signs. + Encode a bytestring to a base64 string for use in URLs. Strip any trailing + equal signs. """ - return base64.urlsafe_b64encode(s).rstrip(b'\n=') + return base64.urlsafe_b64encode(s).rstrip(b'\n=').decode('ascii') def urlsafe_base64_decode(s): @@ -231,7 +230,7 @@ def urlsafe_base64_decode(s): Decode a base64 encoded string. Add back any trailing equal signs that might have been stripped. """ - s = force_bytes(s) + s = s.encode() try: return base64.urlsafe_b64decode(s.ljust(len(s) + len(s) % 4, b'=')) except (LookupError, BinasciiError) as e: |
