Changes between Version 4 and Version 7 of Ticket #28796
- Timestamp:
- Nov 15, 2017, 9:52:46 AM (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #28796
- Property Component Utilities → Core (URLs)
- Property Summary django.utils.http.urlsafe_base64_encode() broken in Django 2.0 → reverse() coerces bytes in args/kwargs to str which adds "b" prefixes to the ouput
-
Ticket #28796 – Description
v4 v7 1 1 Suppose we have: 2 {{{ 3 import hmac 4 from hashlib import sha384 5 from django.utils.http import urlsafe_base64_encode 2 6 3 hashed_msg = hmac.new(key, msg=message, digestmod=sha384) 4 url = urlsafe_base64_encode(hashed.digest()) 7 hashed_msg = hmac.new(b"secret", msg=b"qwerty", digestmod=sha384) 8 url = urlsafe_base64_encode(hashed_msg.digest()) 9 }}} 10 Now url is a bytes object, say b'asdfwerqwefa'. In django 1.11, bytes-like objects could be used in `reverse()`, creating (say) localhost:8000/asdfwerqwefa 5 11 6 Now url is a bytes object, say b'asdfwerqwefa'. In django 1.11, bytes-like objects could be placed in urls no problem, creating (say) localhost:8000/asdfwerqwefa 7 8 However, in django 2.0, the url becomes (say) 12 However, in Django 2.0, the url becomes (say) 9 13 10 14 localhost:8000/b'asdfwerqwefa' … … 17 21 18 22 To reproduce the bug, type: 19 23 {{{ 20 24 $ ./manage.py shell 21 25 >>> import reproduce 22 26 }}} 23 27 24 28 This bug is present in commit d90936f41a2d7a3361e51fc49be033ba0f05f458, but much before that the 'django.urls.path' doesn't exist, so bisection doesn't work cleanly.