Skip to content
Open
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
3 changes: 3 additions & 0 deletions hexbytes/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def hexstr_to_bytes(hexstr: str) -> bytes:
else:
non_prefixed_hex = hexstr

if not non_prefixed_hex:
return b""

# if the hex string is odd-length, then left-pad it to an even length
if len(hexstr) % 2:
padded_hex = "0" + non_prefixed_hex
Expand Down
5 changes: 5 additions & 0 deletions tests/core/test_hexbytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ def test_hex_inputs(hex_input):
assert_equal(wrapped, expected)


@pytest.mark.parametrize("hex_input", ("", "0x", "0X"))
def test_empty_hex_inputs(hex_input):
assert_equal(HexBytes(hex_input), b"")


def test_pretty_output():
hb = HexBytes(b"\x0f\x1a")
assert repr(hb) == "HexBytes('0x0f1a')"
Expand Down
Loading