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

Serialisation with an empty string as key fails #37

Closed
fornwall opened this issue Mar 26, 2020 · 1 comment · Fixed by #38
Closed

Serialisation with an empty string as key fails #37

fornwall opened this issue Mar 26, 2020 · 1 comment · Fixed by #38

Comments

@fornwall
Copy link
Contributor

fornwall commented Mar 26, 2020

The call json5.dumps({'': 'value'}) fails as shown:

>>> json5.dumps({'': 'value'})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/fornwall/src/pyjson5/json5/lib.py", line 232, in dumps
    _, v = _dumps(obj, skipkeys, ensure_ascii, check_circular,
  File "/Users/fornwall/src/pyjson5/json5/lib.py", line 304, in _dumps
    s = _dump_dict(obj, skipkeys, ensure_ascii,
  File "/Users/fornwall/src/pyjson5/json5/lib.py", line 342, in _dump_dict
    valid_key, key_str = _dumps(key, skipkeys, ensure_ascii, check_circular,
  File "/Users/fornwall/src/pyjson5/json5/lib.py", line 253, in _dumps
    if (is_key and _is_ident(obj) and not quote_keys
  File "/Users/fornwall/src/pyjson5/json5/lib.py", line 442, in _is_ident
    if not _is_id_start(k[0]) and k[0] not in (u'$', u'_'):
IndexError: string index out of range

It should behave as the json module:

>>> json.dumps({'': 'value'})
'{"": "value"}'
@dpranke
Copy link
Owner

dpranke commented Mar 26, 2020

I've also pushed v0.9.4 to pypi to include this fix. Thanks again!

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

Successfully merging a pull request may close this issue.

2 participants