Order import: handle mixed endings of last line (Z#23230806) (#6066)

* handle mixed line endings in import

* formatting
This commit is contained in:
Lukas Bockstaller
2026-04-08 13:25:38 +02:00
committed by GitHub
parent c037fd865b
commit 5c7104634e
2 changed files with 31 additions and 0 deletions

View File

@@ -70,6 +70,10 @@ def parse_csv(file, length=None, mode="strict", charset=None):
except ImportError:
charset = file.charset
data = data.decode(charset or "utf-8", mode)
# remove stray linebreaks from the end of the file
data = data.rstrip("\n")
# If the file was modified on a Mac, it only contains \r as line breaks
if '\r' in data and '\n' not in data:
data = data.replace('\r', '\n')