gh-127740: For odd-length input to bytes.fromhex(...) change the error message to ValueError: fromhex() arg must be of even length (#127756)

This commit is contained in:
Srinivas Reddy Thatiparthy (తాటిపర్తి శ్రీనివాస్ రెడ్డి) 2024-12-11 13:05:17 +05:30 committed by GitHub
parent 12b4f1a5a1
commit db9bea0386
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 23 additions and 4 deletions

View file

@ -459,6 +459,12 @@ class BaseBytesTest:
self.assertRaises(ValueError, self.type2test.fromhex, '\x00')
self.assertRaises(ValueError, self.type2test.fromhex, '12 \x00 34')
# For odd number of character(s)
for value in ("a", "aaa", "deadbee"):
with self.assertRaises(ValueError) as cm:
self.type2test.fromhex(value)
self.assertIn("fromhex() arg must contain an even number of hexadecimal digits", str(cm.exception))
for data, pos in (
# invalid first hexadecimal character
('12 x4 56', 3),