diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-09-28 06:12:54 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-28 06:12:54 (GMT) |
commit | 7e35081bc828291da5793db49ab45dee4fda5043 (patch) | |
tree | c618c563de39502023315b3ba8c9979839c78903 /Lib/test/test_binascii.py | |
parent | 85ccedc5b57ddda198e7176ba787e3896435c504 (diff) | |
download | cpython-7e35081bc828291da5793db49ab45dee4fda5043.zip cpython-7e35081bc828291da5793db49ab45dee4fda5043.tar.gz cpython-7e35081bc828291da5793db49ab45dee4fda5043.tar.bz2 |
bpo-34736: improve error message for invalid length b64decode inputs (GH-9563)
Improvements:
1. Include the number of valid data characters in the error message.
2. Mention "number of data characters" rather than "length".
https://bugs.python.org/issue34736
(cherry picked from commit 1fba2ffc37da52c08db51fe4360459990b0311c9)
Co-authored-by: Tal Einat <taleinat+github@gmail.com>
Diffstat (limited to 'Lib/test/test_binascii.py')
-rw-r--r-- | Lib/test/test_binascii.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py index 7418a9ce9..8e37d55 100644 --- a/Lib/test/test_binascii.py +++ b/Lib/test/test_binascii.py @@ -3,6 +3,7 @@ import unittest import binascii import array +import re # Note: "*_hex" functions are aliases for "(un)hexlify" b2a_functions = ['b2a_base64', 'b2a_hex', 'b2a_hqx', 'b2a_qp', 'b2a_uu', @@ -127,7 +128,10 @@ class BinASCIITest(unittest.TestCase): # Test base64 with invalid number of valid characters (1 mod 4) def assertInvalidLength(data): - with self.assertRaisesRegex(binascii.Error, r'(?i)invalid.+length'): + n_data_chars = len(re.sub(br'[^A-Za-z0-9/+]', br'', data)) + expected_errmsg_re = \ + r'(?i)Invalid.+number of data characters.+' + str(n_data_chars) + with self.assertRaisesRegex(binascii.Error, expected_errmsg_re): binascii.a2b_base64(self.type2test(data)) assertInvalidLength(b'a') |