kopia lustrzana https://github.com/snarfed/bridgy-fed
common.memcache_key: encode Unicode chars as UTF-8
rodzic
373a92df3e
commit
33e0d0b14a
|
@ -412,4 +412,4 @@ def memcache_key(key):
|
|||
TODO: truncate to 250 *UTF-8* chars, to handle Unicode chars in URLs. Related:
|
||||
pymemcache Client's allow_unicode_keys constructor kwarg.
|
||||
"""
|
||||
return key[:MEMCACHE_KEY_MAX_LEN].replace(' ', '%20')
|
||||
return key[:MEMCACHE_KEY_MAX_LEN].replace(' ', '%20').encode()
|
||||
|
|
|
@ -152,8 +152,9 @@ class CommonTest(TestCase):
|
|||
@patch('common.MEMCACHE_KEY_MAX_LEN', new=10)
|
||||
def test_memcache_key(self):
|
||||
for input, expected in (
|
||||
('foo', 'foo'),
|
||||
('foo-bar-baz', 'foo-bar-ba'),
|
||||
('foo bar', 'foo%20bar'),
|
||||
('foo', b'foo'),
|
||||
('foo-bar-baz', b'foo-bar-ba'),
|
||||
('foo bar', b'foo%20bar'),
|
||||
('☃.net', b'\xe2\x98\x83.net'),
|
||||
):
|
||||
self.assertEqual(expected, common.memcache_key(input))
|
||||
|
|
Ładowanie…
Reference in New Issue