Skip to content
This repository has been archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
Merge pull request #203 from glogiotatidis/handle-unicode
Browse files Browse the repository at this point in the history
Handle unicode
  • Loading branch information
jgmize authored Jul 7, 2016
2 parents cf2beaf + d922f6c commit 553a25f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions snippets/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def key(self):
# being sent.
key_properties = ['{id}-{date}'.format(id=snippet.id, date=snippet.modified.isoformat())
for snippet in self.snippets]

key_properties.extend([
self.client.startpage_version,
self.client.locale,
Expand All @@ -148,8 +149,8 @@ def key(self):
SNIPPET_FETCH_TEMPLATE_HASH,
])

key_string = u'_'.join(unicode(prop) for prop in key_properties)
return hashlib.sha1(key_string).hexdigest()
key_string = u'_'.join(key_properties)
return hashlib.sha1(key_string.encode('utf-8')).hexdigest()

@property
def cache_key(self):
Expand Down
8 changes: 8 additions & 0 deletions snippets/base/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,14 @@ def test_key_snippets(self):

self.assertNotEqual(bundle1.key, bundle2.key)

def test_key_funny_characters(self):
"""
bundle.key should generate even when client contains strange unicode
characters
"""
client = self._client(channel=u'release-cck- \xe2\x80\x9cubuntu\xe2\x80\x9d')
SnippetBundle(client).key

def test_key_startpage_version(self):
"""
bundle.key must be different between bundles if they have
Expand Down

0 comments on commit 553a25f

Please sign in to comment.