Skip to content

Commit

Permalink
Merge pull request #742 from mih/decodebytes
Browse files Browse the repository at this point in the history
fix(`decode_bytes`): always backslashreplace when asked to
  • Loading branch information
mih authored Jul 11, 2024
2 parents bbe6c04 + 7a73d8c commit b20e779
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion datalad_next/itertools/decode_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def handle_decoding_error(position: int,
else:
return (
position + exc.end,
joined_data[:position + exc.start].decode(encoding)
joined_data[position:position + exc.start].decode(encoding)
+ joined_data[position + exc.start:position + exc.end].decode(
encoding,
errors='backslashreplace'
Expand Down
5 changes: 5 additions & 0 deletions datalad_next/itertools/tests/test_decode_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ def test_no_empty_strings():
# check that empty strings are not yielded
r = tuple(decode_bytes([b'\xc3', b'\xb6']))
assert r == ('ö',)


def test_multiple_errors():
r = ''.join(decode_bytes([b'08 War \xaf No \xaf More \xaf Trouble.shn.mp3']))
assert r == '08 War \\xaf No \\xaf More \\xaf Trouble.shn.mp3'

0 comments on commit b20e779

Please sign in to comment.