diff --git a/isort/core.py b/isort/core.py index a07914af..ff8a5c9a 100644 --- a/isort/core.py +++ b/isort/core.py @@ -159,7 +159,9 @@ def process( else: stripped_line = line.strip() if stripped_line and not line_separator: - line_separator = line[len(line.rstrip()) :].replace(" ", "").replace("\t", "") + line_separator = ( + line[len(line.rstrip()) :].replace(" ", "").replace("\t", "").replace("\f", "") + ) for file_skip_comment in FILE_SKIP_COMMENTS: if file_skip_comment in line: diff --git a/tests/unit/test_isort.py b/tests/unit/test_isort.py index 82b7b613..f5862c77 100644 --- a/tests/unit/test_isort.py +++ b/tests/unit/test_isort.py @@ -3443,6 +3443,17 @@ def test_ensure_line_endings_are_preserved_issue_493() -> None: assert isort.code(test_input) == test_input +@pytest.mark.parametrize("ws", [" ", "\t", "\f"]) +def test_line_endings_are_detected_ignoring_whitespace(ws: str) -> None: + """Test to ensure line endings are not converted""" + test_input = f"# foo{ws}\r\nimport a\r\n\r\ncimport z\r\n" + assert isort.code(test_input) == test_input + test_input = f"# foo{ws}\rimport a\r\rcimport z\r" + assert isort.code(test_input) == test_input + test_input = f"# foo{ws}\nimport a\n\ncimport z\n" + assert isort.code(test_input) == test_input + + def test_not_splitted_sections() -> None: whiteline = "\n" stdlib_section = "import unittest\n"