Skip to content

Commit

Permalink
Merge pull request #1205 from grahamlyons/fix-securecookie-bug-with-p…
Browse files Browse the repository at this point in the history
…ython-3

Fix an issue using `securecookie` with Python 3
  • Loading branch information
davidism authored Dec 4, 2017
2 parents ae372e1 + 41248bf commit c9e05d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions tests/contrib/test_securecookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def test_basic_support():
assert not c3.new
assert c3 == {}

c4 = SecureCookie({'x': 42}, 'foo')
c4_serialized = c4.serialize()
assert SecureCookie.unserialize(c4_serialized, 'foo') == c4


def test_wrapper_support():
req = Request.from_values()
Expand Down
4 changes: 2 additions & 2 deletions werkzeug/contrib/securecookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def application(environ, start_response):
from time import time
from hashlib import sha1 as _default_hash

from werkzeug._compat import iteritems, text_type
from werkzeug._compat import iteritems, text_type, to_bytes
from werkzeug.urls import url_quote_plus, url_unquote_plus
from werkzeug._internal import _date_to_unix
from werkzeug.contrib.sessions import ModificationTrackingDict
Expand Down Expand Up @@ -152,7 +152,7 @@ def __init__(self, data=None, secret_key=None, new=True):
# explicitly convert it into a bytestring because python 2.6
# no longer performs an implicit string conversion on hmac
if secret_key is not None:
secret_key = bytes(secret_key)
secret_key = to_bytes(secret_key, 'utf-8')
self.secret_key = secret_key
self.new = new

Expand Down

0 comments on commit c9e05d0

Please sign in to comment.