diff --git a/normalization/test_ufonormalizer.py b/normalization/test_ufonormalizer.py index 5244ec1..d5242d0 100644 --- a/normalization/test_ufonormalizer.py +++ b/normalization/test_ufonormalizer.py @@ -1664,6 +1664,14 @@ def test_subpathWriteFile(self): text = f.read() self.assertEqual(text, expected_text) + def test_subpathWriteFile_newline(self): + mixed_eol_text = 'foo\r\nbar\nbaz\rquz' + expected_text = 'foo\nbar\nbaz\nquz' + subpathWriteFile(mixed_eol_text, self.directory, self.filename) + with open(self.filepath, 'r', encoding='utf-8') as f: + text = f.read() + self.assertEqual(text, expected_text) + def test_subpathWritePlist(self): expected_data = dict([('a', 'foo'), ('b', 'bar'), ('c', '™')]) subpathWritePlist(expected_data, self.directory, self.plistname) diff --git a/normalization/ufonormalizer.py b/normalization/ufonormalizer.py index 9a07244..462bd93 100644 --- a/normalization/ufonormalizer.py +++ b/normalization/ufonormalizer.py @@ -1369,7 +1369,8 @@ def subpathWriteFile(text, ufoPath, *subpath): existing = None if text != existing: - with open(path, "w", encoding="utf-8") as f: + # always use Unix LF end of lines + with open(path, "w", encoding="utf-8", newline="\n") as f: f.write(text) def subpathWritePlist(data, ufoPath, *subpath):