Skip to content

Commit

Permalink
Relax error handling scheme.
Browse files Browse the repository at this point in the history
  • Loading branch information
denpamusic committed Jul 31, 2024
1 parent db32a49 commit f135302
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyplumio/helpers/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def pack(self) -> bytes:

def unpack(self, data: bytes) -> None:
"""Unpack the data."""
self._value = data.split(b"\0", 1)[0].decode()
self._value = data.split(b"\0", 1)[0].decode("utf-8", "replace")
self._size = len(self.value) + 1


Expand Down
6 changes: 6 additions & 0 deletions tests/helpers/test_data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ def test_string() -> None:
assert data_type == data_types.String.from_bytes(buffer)
assert data_type == "test"

# Test with unknown unicode char.
buffer = b"test\xd8\x00"
data_type = data_types.String.from_bytes(buffer)
assert data_type.value == "test�"
assert data_type.size == 6


def test_var_bytes() -> None:
"""Test a variable bytes data type."""
Expand Down

0 comments on commit f135302

Please sign in to comment.