# HG changeset patch # User Brian Neal # Date 1528419193 18000 # Node ID ba3230aba90c8f1d7133a998757031b5a08826c9 # Parent a1a223ab0c8f56bc113e2ca2eecb10e3e765f60d Fix unicode error with wiki cookie processing diff -r a1a223ab0c8f -r ba3230aba90c wiki/middleware.py --- a/wiki/middleware.py Sat Apr 14 14:03:04 2018 -0500 +++ b/wiki/middleware.py Thu Jun 07 19:53:13 2018 -0500 @@ -23,16 +23,18 @@ # The key part of the cookie is just a string that would make things # difficult for a spoofer; something that can't be easily made up: + username = user.username.encode('utf-8') + email = user.email.encode('utf-8') h = hashlib.sha256() - h.update(user.username.encode('utf-8')) - h.update(user.email.encode('utf-8')) + h.update(username) + h.update(email) h.update(now.isoformat()) h.update(''.join(random.sample(string.printable, 64))) h.update(settings.SECRET_KEY) key = h.hexdigest() - parts = (user.username, user.email, key) + parts = (username, email, key) return '#'.join(parts) diff -r a1a223ab0c8f -r ba3230aba90c wiki/tests/test_middleware.py --- a/wiki/tests/test_middleware.py Sat Apr 14 14:03:04 2018 -0500 +++ b/wiki/tests/test_middleware.py Thu Jun 07 19:53:13 2018 -0500 @@ -1,3 +1,4 @@ +# coding=utf-8 """ Tests for the wiki integration application. @@ -20,8 +21,8 @@ def setUp(self): self.factory = RequestFactory() - self.user = User.objects.create_user('test_user', 'test@example.com', - 'password') + self.user = User.objects.create_user(u'Sérgio', u'test@example.com', + u'password') self.conn = get_redis_connection() self.mw = WikiMiddleware() @@ -52,7 +53,7 @@ cookie_val = cookie.value try: - user, email, key = cookie_val.split('#') + user, email, key = cookie_val.decode('utf-8').split('#') except ValueError: self.fail('invalid cookie value') else: