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

Missing newline at end of file with multiple array of tables can corrupt during dumping #381

Open
gdiepen opened this issue Sep 20, 2024 · 0 comments

Comments

@gdiepen
Copy link

gdiepen commented Sep 20, 2024

When creating a pipeline using pipenv, I ran into a weird situation where the Pipfile would get corrupted in certain cases, when there would be multiple entries in an array of tables and the last one was at the end of the file AND that does not have a final newline at the end

The following python code reproduces the problem with tomlkit 0.13.2

import tomlkit

toml_str = '''[[products]]
name = "Hammer"

[foo]

[bar]

[[products]]
name = "Nail"'''

parsed = tomlkit.loads(toml_str)

print(tomlkit.dumps(parsed))

Running this python code will give the following (wrong) output:

[[products]]
name = "Hammer"

[[products]]
name = "Nail"[foo]

[bar]

As you can see, the foo table entry is put directly after the last entry of products

If you add a trailing newline at the end of the file, this problem does not occur.

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