Skip to content
Open
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
5 changes: 3 additions & 2 deletions pymemcache/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ def check_key_helper(

if len(key) > 250:
raise MemcacheIllegalInputError("Key is too long: %r" % key)
# second statement catches leading or trailing whitespace
elif len(parts) > 1 or (parts and parts[0] != key):
# second statement catches leading or trailing whitespace; the third
# catches keys made only of whitespace, for which split() is empty (#662)
elif len(parts) > 1 or (parts and parts[0] != key) or (key and not parts):
raise MemcacheIllegalInputError("Key contains whitespace: %r" % key)
elif b"\00" in key:
raise MemcacheIllegalInputError("Key contains null: %r" % key)
Expand Down
5 changes: 5 additions & 0 deletions pymemcache/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ def is_ipv6(address):
[
("b" * 251, True, b"", MemcacheIllegalInputError, "Key is too long"),
("foo bar", True, b"", MemcacheIllegalInputError, "Key contains whitespace"),
(" ", True, b"", MemcacheIllegalInputError, "Key contains whitespace"),
("\t", True, b"", MemcacheIllegalInputError, "Key contains whitespace"),
("\r\n", True, b"", MemcacheIllegalInputError, "Key contains whitespace"),
(" \r\n ", True, b"", MemcacheIllegalInputError, "Key contains whitespace"),
(b" ", True, b"", MemcacheIllegalInputError, "Key contains whitespace"),
("\00", True, b"", MemcacheIllegalInputError, "Key contains null"),
(None, True, b"", TypeError, None),
],
Expand Down