Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an issue using securecookie with Python 3 #1205

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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