Skip to content

Commit b73d192

Browse files
Fix: Inconsistent newlines on Windows (#402)
* Update test_toml_file.py * Update toml_file.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 564b5a8 commit b73d192

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

tests/test_toml_file.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,13 @@ def test_default_eol_is_os_linesep(tmpdir):
105105
linesep = os.linesep.encode()
106106
with open(toml_path, "rb") as f:
107107
assert f.read() == b"a = 1" + linesep + b"b = 2" + linesep
108+
109+
110+
def test_readwrite_eol_windows(tmpdir):
111+
toml_path = str(tmpdir / "pyproject.toml")
112+
doc = TOMLDocument()
113+
doc.add("a", 1)
114+
f = TOMLFile(toml_path)
115+
f.write(doc)
116+
readback = f.read()
117+
assert doc.as_string() == readback.as_string()

tomlkit/toml_file.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def read(self) -> TOMLDocument:
3737
num_win_eol = content.count("\r\n")
3838
if num_win_eol == num_newline:
3939
self._linesep = "\r\n"
40+
content = content.replace("\r\n", "\n")
4041
elif num_win_eol == 0:
4142
self._linesep = "\n"
4243
else:

0 commit comments

Comments
 (0)