Skip to content

Commit 88cc6cb

Browse files
claudespoorcc
authored andcommitted
fix: address review feedback and codespell CI failure on #1384
- Preserve valid CP1252 bytes (e.g. 0xe9) in the final decode fallback instead of losing them to a UTF-8 replace pass. - Rename a test fixture from "café.txt" written as caf\xe9.txt, which codespell's tokenizer read as the standalone word "caf" and flagged as a typo for "calf". - Add a docstring to test_decode_subprocess_output and a regression case mixing a valid CP1252 byte with an undefined one.
1 parent 890cedc commit 88cc6cb

3 files changed

Lines changed: 4 additions & 5 deletions

File tree

dfetch/util/cmdline.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ def decode_subprocess_output(data: bytes) -> str:
5050
return data.decode()
5151
except UnicodeDecodeError:
5252
pass
53-
try:
54-
return data.decode(encoding="cp1252")
55-
except UnicodeDecodeError:
56-
return data.decode(errors="replace")
53+
return data.decode(encoding="cp1252", errors="replace")
5754

5855

5956
def run_on_cmdline(

tests/test_cmdline.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def test_run_on_cmdline(name, cmd, cmd_result, expectation):
5656
("utf-8", "café".encode(), "café"),
5757
("cp1252 fallback", "café".encode("cp1252"), "café"),
5858
("undefined in both codecs is replaced", b"\x81", "�"),
59+
("valid cp1252 byte survives next to an undefined one", b"\xe9\x81", "é�"),
5960
],
6061
)
6162
def test_decode_subprocess_output(name, data, expected):
63+
"""Decode UTF-8 and CP1252 output, replacing bytes undecodable in both."""
6264
assert decode_subprocess_output(data) == expected, name

tests/test_svn_vcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def test_export_tolerates_non_utf8_output():
127127
completing.
128128
"""
129129
with patch("dfetch.vcs.svn.run_on_cmdline") as mock_run:
130-
mock_run.return_value.stdout = b"A caf\xe9.txt\n"
130+
mock_run.return_value.stdout = b"A r\xe9sum\xe9.txt\n"
131131
SvnRepo.export("svn://example.com/repo", dst="/tmp/out")
132132

133133

0 commit comments

Comments
 (0)