Skip to content

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

@gdiepen

Description

@gdiepen

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions