Skip to content

Commit c6dab1f

Browse files
committed
fix(debug): debug output doesn't mis-handle odd line separators #2296
1 parent 08fbc32 commit c6dab1f

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

‎coverage/debug.py‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -373,15 +373,12 @@ def filter_text(text: str, filters: Iterable[Callable[[str], str]]) -> str:
373373
run.
374374
375375
"""
376-
clean_text = text.rstrip()
377-
ending = text[len(clean_text) :]
378-
text = clean_text
379376
for filter_fn in filters:
380377
lines = []
381-
for line in text.splitlines():
382-
lines.extend(filter_fn(line).splitlines())
383-
text = "\n".join(lines)
384-
return text + ending
378+
for line in text.splitlines(keepends=True):
379+
lines.extend(filter_fn(line).splitlines(keepends=True))
380+
text = "".join(lines)
381+
return text
385382

386383

387384
class CwdTracker:

‎tests/test_debug.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,14 @@ def test_clipped_repr(text: str, numchars: int, result: str) -> None:
124124
("hello\nbye\n", [lambda x: "=" + x], "=hello\n=bye\n"),
125125
(
126126
"hello\nbye\n",
127-
[lambda x: "=" + x, lambda x: x + "\ndone\n"],
127+
[lambda x: "=" + x, lambda x: x + "done\n"],
128128
"=hello\ndone\n=bye\ndone\n",
129129
),
130+
(
131+
"1\x0b\u3001\n2\x0chello\u2028bye\n",
132+
[lambda x: "=" + x],
133+
"=1\x0b=\u3001\n=2\x0c=hello\u2028=bye\n",
134+
),
130135
],
131136
)
132137
def test_filter_text(

0 commit comments

Comments
 (0)