Skip to content

Commit da99709

Browse files
authored
Merge pull request #2436 from robsdedude/fix/line-ending-detection
Fix line separator detection not considering form feed as white space
2 parents 17746ba + e5faa30 commit da99709

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

isort/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ def process(
159159
else:
160160
stripped_line = line.strip()
161161
if stripped_line and not line_separator:
162-
line_separator = line[len(line.rstrip()) :].replace(" ", "").replace("\t", "")
162+
line_separator = (
163+
line[len(line.rstrip()) :].replace(" ", "").replace("\t", "").replace("\f", "")
164+
)
163165

164166
for file_skip_comment in FILE_SKIP_COMMENTS:
165167
if file_skip_comment in line:

tests/unit/test_isort.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3443,6 +3443,17 @@ def test_ensure_line_endings_are_preserved_issue_493() -> None:
34433443
assert isort.code(test_input) == test_input
34443444

34453445

3446+
@pytest.mark.parametrize("ws", [" ", "\t", "\f"])
3447+
def test_line_endings_are_detected_ignoring_whitespace(ws: str) -> None:
3448+
"""Test to ensure line endings are not converted"""
3449+
test_input = f"# foo{ws}\r\nimport a\r\n\r\ncimport z\r\n"
3450+
assert isort.code(test_input) == test_input
3451+
test_input = f"# foo{ws}\rimport a\r\rcimport z\r"
3452+
assert isort.code(test_input) == test_input
3453+
test_input = f"# foo{ws}\nimport a\n\ncimport z\n"
3454+
assert isort.code(test_input) == test_input
3455+
3456+
34463457
def test_not_splitted_sections() -> None:
34473458
whiteline = "\n"
34483459
stdlib_section = "import unittest\n"

0 commit comments

Comments
 (0)