diff --git a/tests/contrib/test_securecookie.py b/tests/contrib/test_securecookie.py index 8a6613695..41928167a 100644 --- a/tests/contrib/test_securecookie.py +++ b/tests/contrib/test_securecookie.py @@ -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() diff --git a/werkzeug/contrib/securecookie.py b/werkzeug/contrib/securecookie.py index bc757261b..5927e2b0b 100644 --- a/werkzeug/contrib/securecookie.py +++ b/werkzeug/contrib/securecookie.py @@ -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 @@ -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