Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion isort/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down