Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rwarren opened this issue Mar 23, 2015 · 1 comment
Open

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

rwarren opened this issue Mar 23, 2015 · 1 comment

Comments

@rwarren
Copy link

rwarren commented Mar 23, 2015

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
Copy link
Author

rwarren commented Mar 24, 2015

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

if (!Encoder_writeByte(context, EMPTY_STRING_TYPE))

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant