File tree Expand file tree Collapse file tree 3 files changed +11
-2
lines changed Expand file tree Collapse file tree 3 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 10
10
from email .utils import formatdate
11
11
12
12
from django .utils .datastructures import MultiValueDict
13
- from django .utils .encoding import force_str , force_text
13
+ from django .utils .encoding import force_bytes , force_str , force_text
14
14
from django .utils .functional import allow_lazy
15
15
from django .utils import six
16
16
from django .utils .six .moves .urllib .parse import (
@@ -224,7 +224,7 @@ def urlsafe_base64_decode(s):
224
224
Decodes a base64 encoded string, adding back any trailing equal signs that
225
225
might have been stripped.
226
226
"""
227
- s = s . encode ( 'utf-8' ) # base64encode should only return ASCII.
227
+ s = force_bytes ( s )
228
228
try :
229
229
return base64 .urlsafe_b64decode (s .ljust (len (s ) + len (s ) % 4 , b'=' ))
230
230
except (LookupError , BinasciiError ) as e :
Original file line number Diff line number Diff line change @@ -103,3 +103,6 @@ Bugfixes
103
103
104
104
* Fixed missing ``get_or_create`` and ``update_or_create`` on related managers
105
105
causing ``IntegrityError`` (:ticket:`23611`).
106
+
107
+ * Made :func:`~django.utils.http.urlsafe_base64_decode` return the proper
108
+ type (byte string) on Python 3 (:ticket:`23333`).
Original file line number Diff line number Diff line change @@ -119,6 +119,12 @@ def test_is_safe_url(self):
119
119
'/url%20with%20spaces/' ):
120
120
self .assertTrue (http .is_safe_url (good_url , host = 'testserver' ), "%s should be allowed" % good_url )
121
121
122
+ def test_urlsafe_base64_roundtrip (self ):
123
+ bytestring = b'foo'
124
+ encoded = http .urlsafe_base64_encode (bytestring )
125
+ decoded = http .urlsafe_base64_decode (encoded )
126
+ self .assertEqual (bytestring , decoded )
127
+
122
128
123
129
class ETagProcessingTests (unittest .TestCase ):
124
130
def test_parsing (self ):
You can’t perform that action at this time.
0 commit comments