What are the memcache control characters?

1,746 views
Skip to first unread message

Patrick May

unread,
Mar 10, 2009, 7:11:38 PM3/10/09
to memcached
I'm writing a filter (appside) to filter out "control characters".
I've got a feeling that the colon is one (":"). But are there any
other control characters? What's the complete list of memcache
control characters which are disallowed in keys?

Thanks for the great tool!

- patrick may

Henrik Schröder

unread,
Mar 10, 2009, 9:05:14 PM3/10/09
to memc...@googlegroups.com
Hi Patrick,

The protocol docs say that they key must not include control characters or whitespace, but as far as I can tell, the only really disallowed characters are space, CR and LF. Colon is absolutely not disallowed, simple testing shows you this:

set foo:bar 0 0 5
abcde
STORED
get foo:bar
VALUE foo:bar 0 5
abcde
END

Even TAB worked fine for me, so so much for the "no whitespace" rule:

set foo^Ibar 0 0 5
12345
STORED
get foo^Ibar
VALUE foo       bar 0 5
12345
END

Control characters are fine too:

set foo^Gbar 0 0 4
beep
STORED
get foo^Gbar
VALUE foobar 0 4
beep
END


This is against version 1.2.5 on Windows, I hardly think other versions work differently, but different clients may or may not handle it nicely, so if you want to be safe, just strip out all characters at or below 32.


/Henrik

Dustin

unread,
Mar 10, 2009, 9:05:53 PM3/10/09
to memcached

On Mar 10, 3:11 pm, Patrick May <patsp...@gmail.com> wrote:
> I'm writing a filter (appside) to filter out "control characters".
> I've got a feeling that the colon is one (":").  But are there any
> other control characters?  What's the complete list of memcache
> control characters which are disallowed in keys?

This is referring to the standard definition of control characters:

http://en.wikipedia.org/wiki/Control_character

I don't believe it's *strictly* checked, but if you fall outside of
the right character set, we can't promise anything...

Dean Harding

unread,
Mar 10, 2009, 10:36:20 PM3/10/09
to memc...@googlegroups.com
> the only really disallowed characters are space, CR
> and LF.

I would at 0x00 to that list (I'm pretty sure it doesn't handle that
correctly, but I've never tried....)

I just use a "remove everything whose ASCII value is <= 0x20" rule and it
seems to work fine.

Dean.


Trond Norbye

unread,
Mar 11, 2009, 3:50:22 AM3/11/09
to memc...@googlegroups.com
Henrik Schröder wrote:
> Hi Patrick,
>
> The protocol docs say that they key must not include control
> characters or whitespace, but as far as I can tell, the only really
> disallowed characters are space, CR and LF. Colon is absolutely not
> disallowed, simple testing shows you this:
In the binary protocol the key is specified with a length, so the key
may contain all byte values.

Cheers,

Trond

Henrik Schröder

unread,
Mar 11, 2009, 5:27:44 AM3/11/09
to memc...@googlegroups.com
On Wed, Mar 11, 2009 at 03:36, Dean Harding <dean.h...@dload.com.au> wrote:

I would at 0x00 to that list (I'm pretty sure it doesn't handle that
correctly, but I've never tried....)



I had to test it, and I can now confirm that, indeed, as suspected, that character cannot be used in the key. You may now all sleep soundly in the knowledge that we went to the bottom of this, leaving no stone unturned, answering all questions. Thank you, thank you, and good night.

:-)


/Henrik
Reply all
Reply to author
Forward
0 new messages