Changes between Version 4 and Version 7 of Ticket #28796


Ignore:
Timestamp:
Nov 15, 2017, 9:52:46 AM (7 years ago)
Author:
Tim Graham
Comment:

I think we could document the backwards incompatibility and point out the solution to add .decode(), which should also work without older versions of Django. Does it seem okay, Nick?

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #28796

    • Property Component UtilitiesCore (URLs)
    • Property Summary django.utils.http.urlsafe_base64_encode() broken in Django 2.0reverse() coerces bytes in args/kwargs to str which adds "b" prefixes to the ouput
  • Ticket #28796 – Description

    v4 v7  
    11Suppose we have:
     2{{{
     3import hmac
     4from hashlib import sha384
     5from django.utils.http import urlsafe_base64_encode
    26
    3 hashed_msg = hmac.new(key, msg=message, digestmod=sha384)
    4 url = urlsafe_base64_encode(hashed.digest())
     7hashed_msg = hmac.new(b"secret", msg=b"qwerty", digestmod=sha384)
     8url = urlsafe_base64_encode(hashed_msg.digest())
     9}}}
     10Now 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
    511
    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)
     12However, in Django 2.0, the url becomes (say)
    913
    1014localhost:8000/b'asdfwerqwefa'
     
    1721
    1822To reproduce the bug, type:
    19 
     23{{{
    2024$ ./manage.py shell
    2125>>> import reproduce
    22 
     26}}}
    2327
    2428This bug is present in commit d90936f41a2d7a3361e51fc49be033ba0f05f458, but much before that the 'django.urls.path' doesn't exist, so bisection doesn't work cleanly.
Back to Top