mirror of
https://github.com/meshtastic/python.git
synced 2025-12-29 02:47:53 -05:00
fix unrelated bug when fromStr input is short hex
For example, 0x0 will generate an unhandled ValueError. This was caught during a random unit test run for 3.9, so I figure I'd fix it. This is unrelated to the PR otherwise.
This commit is contained in:
@@ -650,3 +650,11 @@ def test_fuzz_fromStr(valstr):
|
||||
assert isinstance(result, int)
|
||||
except ValueError:
|
||||
assert isinstance(result, str)
|
||||
|
||||
def test_shorthex():
|
||||
result = fromStr('0x0')
|
||||
assert result == b'\x00'
|
||||
result = fromStr('0x5')
|
||||
assert result == b'\x05'
|
||||
result = fromStr('0xffff')
|
||||
assert result == b'\xff\xff'
|
||||
@@ -82,7 +82,7 @@ def fromStr(valstr):
|
||||
val = bytes()
|
||||
elif valstr.startswith("0x"):
|
||||
# if needed convert to string with asBytes.decode('utf-8')
|
||||
val = bytes.fromhex(valstr[2:])
|
||||
val = bytes.fromhex(valstr[2:].zfill(2))
|
||||
elif valstr.startswith("base64:"):
|
||||
val = base64.b64decode(valstr[7:])
|
||||
elif valstr.lower() in {"t", "true", "yes"}:
|
||||
|
||||
Reference in New Issue
Block a user