Skip to content

fix: raise the intended ValueError for non-ascii hex strings - #67

Draft
nikolauspschuetz wants to merge 1 commit into
ApeWorX:mainfrom
nikolauspschuetz:fix-hexstr-encode-exception
Draft

fix: raise the intended ValueError for non-ascii hex strings#67
nikolauspschuetz wants to merge 1 commit into
ApeWorX:mainfrom
nikolauspschuetz:fix-hexstr-encode-exception

Conversation

@nikolauspschuetz

Copy link
Copy Markdown

hexstr_to_bytes guards padded_hex.encode("ascii") with except UnicodeDecodeError, but str.encode raises UnicodeEncodeError — so the handler never runs and a non-ascii hex string surfaces the raw codec error instead of the intended ValueError:

>>> HexBytes("0x0é")
UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in position 1: ordinal not in range(128)

Correcting the caught type raises the message the handler was written for — ValueError: hex string 0é may only contain [0-9a-fA-F] characters. Valid hex is unaffected. Added a regression test (there was none for non-ascii input).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant