limscoder / amfast

An Adobe AMF serialization and RPC implementation for Python, written as a C extension for speed.
MIT License
5 stars 6 forks source link

Empty string is a legitimate dict key, but amfast ignores it #86

Open rwarren opened 9 years ago

rwarren commented 9 years ago

See this complete example:

>>> from amfast.encoder import Encoder
>>> from amfast.decoder import Decoder
>>> encoder = Encoder(amf3 = True)
>>> decoder = Decoder(amf3 = True)
>>> encode = encoder.encode
>>> decode = decoder.decode
>>> decode(encode({"a": 1}))
{u'a': 1}
>>> decode(encode({"": 1}))
{}
>>> d = {"a": 1, "": 2}
>>> d
{'': 2, 'a': 1}
>>> decode(encode(d))
{u'a': 1}

I'm currently running AmFast==0.5.3-r546

rwarren commented 9 years ago

Root seems to be that the dict encoding is done via the amf3 Object type, where the terminator for keys is EMPTY_STRING_TYPE:

https://github.com/limscoder/amfast/blob/e215a6dc650a78e07ccecc14f73fd262a56ffa0b/amfast/ext_src/encoder.c#L618

I'm wondering if, in the case of a key that is actually an empty string, a fully specified zero length string (with encode_string) would avoid the problem. Presumably the end-of-keys marker is EMPTY_STRING_TYPE specifically?

I don't follow the code (or spec) that well, so there may obviously be a better way.