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

dumps producing invalid output #143

Closed
abravalheri opened this issue Sep 17, 2021 · 0 comments · Fixed by #151
Closed

dumps producing invalid output #143

abravalheri opened this issue Sep 17, 2021 · 0 comments · Fixed by #151

Comments

@abravalheri
Copy link
Contributor

Hello, I have been recently working with TOML and I notice dumps produce an invalid output (not according to the v1.0.0 standard). loads is also not able to parse the produced output.

The steps to reproduce this issue are:

>>> import tomlkit
>>> tomlkit.dumps({"": "src"})
' = "src"\n'

>>> tomlkit.loads(tomlkit.dumps({"": "src"}))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".venv/lib/python3.8/site-packages/tomlkit/api.py", line 34, in loads
    return parse(string)
  File ".venv/lib/python3.8/site-packages/tomlkit/api.py", line 51, in parse
    return Parser(string).parse()
  File ".venv/lib/python3.8/site-packages/tomlkit/parser.py", line 146, in parse
    item = self._parse_item()
  File ".venv/lib/python3.8/site-packages/tomlkit/parser.py", line 306, in _parse_item
    return self._parse_key_value(True)
  File ".venv/lib/python3.8/site-packages/tomlkit/parser.py", line 378, in _parse_key_value
    key = self._parse_key()
  File ".venv/lib/python3.8/site-packages/tomlkit/parser.py", line 422, in _parse_key
    return self._parse_bare_key()
  File ".venv/lib/python3.8/site-packages/tomlkit/parser.py", line 474, in _parse_bare_key
    raise self.parse_error(ParseError, "Empty key found")
tomlkit.exceptions.ParseError: Empty key found at line 1 col 1

Empty key found at line 1 col 1

Please notice the standard explicit allows the usage of empty keys, and I believe the expected behaviour should be dumps({"": "src"}) #=> "" = "src".

I am using Python 3.8.0 and tomlkit 0.7.2 on Ubuntu 18.04.5 LTS
Please let me know if any other information is needed.

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.

1 participant