diff options
author | Glenn Moloney <glenn.moloney@gmail.com> | 2024-08-13 08:38:20 +1000 |
---|---|---|
committer | Glenn Moloney <glenn.moloney@gmail.com> | 2024-08-19 14:18:34 +1000 |
commit | 6367099f8365c22b42474818ce5fdb9b35591ade (patch) | |
tree | 9784e255a91ef704201d149194753938598cffa3 /tests/basics/builtin_str_hex.py | |
parent | e9814e987bcc816fb67e38748a5afce466c45606 (diff) |
py/objstr: Skip whitespace in bytes.fromhex().
Skip whitespace characters between pairs of hex numbers.
This makes `bytes.fromhex()` compatible with cpython.
Includes simple test in `tests/basic/builtin_str_hex.py`.
Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
Diffstat (limited to 'tests/basics/builtin_str_hex.py')
-rw-r--r-- | tests/basics/builtin_str_hex.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/basics/builtin_str_hex.py b/tests/basics/builtin_str_hex.py index 7390c8eae..945588301 100644 --- a/tests/basics/builtin_str_hex.py +++ b/tests/basics/builtin_str_hex.py @@ -20,5 +20,20 @@ for x in ( "08090a0b0c0d0e0f", "7f80ff", "313233344142434461626364", + "ab\tcd\n ef ", + "ab cd ef", + "ab cd ef ", + " ab cd ef ", + # Invalid hex strings: + "abcde", # Odd number of hex digits + "ab cd e", + "a b cd ef", # Spaces between hex pairs + "ab cd e f ", + "abga", # Invalid hex digits + "ab_cd", + "ab:cd", ): - print(bytes.fromhex(x)) + try: + print(bytes.fromhex(x)) + except ValueError as e: + print("ValueError:", e) |