Skip to content

Commit fe9d227

Browse files
committed
style/docs: finish and document #2142
1 parent e06eb34 commit fe9d227

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

CHANGES.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ upgrading your version of coverage.py.
2323
Unreleased
2424
----------
2525

26-
Nothing yet.
26+
- Fix: the markdown-formatted coverage report didn't fully escape special
27+
characters in file paths (`issue 2141`_). This would be very unlikely to
28+
cause a problem, but now it's done properly, thanks to `Ellie Ayla
29+
<pull 2142_>`_.
2730

31+
.. _issue 2141: https://github.com/coveragepy/coveragepy/issues/2141
32+
.. _pull 2142: https://github.com/coveragepy/coveragepy/pull/2142
2833

2934
.. start-releases
3035

CONTRIBUTORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ Edgar Ramírez Mondragón
8484
Eduardo Schettino
8585
Edward Loper
8686
Eli Skeggs
87+
Ellie Ayla
8788
Emil Madsen
8889
Éric Larivière
8990
Federico Bond

coverage/report.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
from __future__ import annotations
77

8+
import string
89
import sys
910
from collections.abc import Iterable
10-
from string import punctuation
1111
from typing import IO, TYPE_CHECKING, Any
1212

1313
from coverage.exceptions import ConfigError, NoDataError
@@ -20,14 +20,14 @@
2020
if TYPE_CHECKING:
2121
from coverage import Coverage
2222

23-
ESCAPE_PUNCTUATION_TABLE = "".maketrans(
24-
{char: f"\\{char}" for char in punctuation if char not in ".,/-"}
23+
MARKDOWN_ESCAPES = str.maketrans(
24+
{char: f"\\{char}" for char in string.punctuation if char not in ".,/-"}
2525
)
2626

2727

2828
def escape_markdown(text: str) -> str:
2929
"""Prefix all characters meaningful in markdown tables with backslashes."""
30-
return text.translate(ESCAPE_PUNCTUATION_TABLE)
30+
return text.translate(MARKDOWN_ESCAPES)
3131

3232

3333
class SummaryReporter:

tests/coveragetest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ def start_import_stop(
126126
return mod
127127

128128
def get_report(
129-
self, cov: Coverage, squeeze: bool = True, output_format: str | None = None, **kwargs: Any
129+
self,
130+
cov: Coverage,
131+
squeeze: bool = True,
132+
output_format: str | None = None,
133+
**kwargs: Any,
130134
) -> str:
131135
"""Get the report from `cov`, and canonicalize it."""
132136
repout = io.StringIO()

tests/test_report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ def test_report_with_chdir(self) -> None:
905905
id="cross-platform-punctuation",
906906
),
907907
pytest.param(
908-
"\\", # seperate only to make test failure messages easy to read
908+
"\\", # separate only to make test failure messages easy to read
909909
set("\\"),
910910
"/", # munged to forward slash by get_report
911911
id="backslash-untouched",

0 commit comments

Comments
 (0)