Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Version 2.8.1

(released on 2026-01-24)

- Don't attempt to UTF-8-decode binary values.

## Version 2.8.0

(released on 2026-01-24)
Expand Down
11 changes: 1 addition & 10 deletions cli_helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@ def bytes_to_string(b):

"""
if isinstance(b, binary_type):
needs_hex = False
try:
result = b.decode("utf8")
needs_hex = not result.isprintable()
except UnicodeDecodeError:
needs_hex = True
if needs_hex:
return "0x" + binascii.hexlify(b).decode("ascii")
else:
return result
return "0x" + binascii.hexlify(b).decode("ascii")
return b


Expand Down
2 changes: 1 addition & 1 deletion tests/tabular_output/test_preprocessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_bytes_to_string():
"""Test the bytes_to_string() function."""
data = [[1, "John"], [2, b"Jill"]]
headers = [0, "name"]
expected = ([[1, "John"], [2, "Jill"]], [0, "name"])
expected = ([[1, "John"], [2, "0x4a696c6c"]], [0, "name"])
results = bytes_to_string(data, headers)

assert expected == (list(results[0]), results[1])
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_bytes_to_string_hexlify():

def test_bytes_to_string_decode_bytes():
"""Test that bytes_to_string() decodes bytes."""
assert utils.bytes_to_string(b"foobar") == "foobar"
assert utils.bytes_to_string(b"foobar") == "0x666f6f626172"


def test_bytes_to_string_unprintable():
Expand All @@ -31,7 +31,7 @@ def test_bytes_to_string_non_bytes():

def test_to_string_bytes():
"""Test that to_string() converts bytes to a string."""
assert utils.to_string(b"foo") == "foo"
assert utils.to_string(b"foo") == "0x666f6f"


def test_to_string_non_bytes():
Expand Down
Loading