https://github.com/python/cpython/commit/d0e204fb1da2ba7956ec2dff6501c3374eee1d43
commit: d0e204fb1da2ba7956ec2dff6501c3374eee1d43
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-04-06T13:47:27+03:00
summary:
gh-148153: Do not use assert for parameter validation in base64 (GH-148154)
base64.b32encode() now always raises ValueError instead of
AssertionError for the value of map01 with invalid length.
files:
A Misc/NEWS.d/next/Library/2026-04-06-11-20-24.gh-issue-148153.ZtsuTl.rst
M Doc/library/base64.rst
M Lib/base64.py
M Lib/test/test_base64.py
diff --git a/Doc/library/base64.rst b/Doc/library/base64.rst
index 425dff8f2a9ad1..6e6e5d603e37b1 100644
--- a/Doc/library/base64.rst
+++ b/Doc/library/base64.rst
@@ -69,9 +69,6 @@ POST request.
after at most every *wrapcol* characters.
If *wrapcol* is zero (default), do not insert any newlines.
- May assert or raise a :exc:`ValueError` if the length of *altchars* is not
2. Raises a
- :exc:`TypeError` if *altchars* is not a :term:`bytes-like object`.
-
.. versionchanged:: 3.15
Added the *padded* and *wrapcol* parameters.
diff --git a/Lib/base64.py b/Lib/base64.py
index a94bec4d031c52..7f39c68070b5da 100644
--- a/Lib/base64.py
+++ b/Lib/base64.py
@@ -237,7 +237,6 @@ def b32decode(s, casefold=False, map01=None, *,
padded=True, ignorechars=b''):
# either L (el) or I (eye).
if map01 is not None:
map01 = _bytes_from_decode_data(map01)
- assert len(map01) == 1, repr(map01)
s = s.translate(bytes.maketrans(b'01', b'O' + map01))
if casefold:
s = s.upper()
diff --git a/Lib/test/test_base64.py b/Lib/test/test_base64.py
index 1a4dd56a553f4d..868abcfee24e10 100644
--- a/Lib/test/test_base64.py
+++ b/Lib/test/test_base64.py
@@ -607,6 +607,11 @@ def test_b32decode_map01(self):
self.assertRaises(binascii.Error, base64.b32decode, b'M1O23456')
self.assertRaises(binascii.Error, base64.b32decode, b'ML023456')
self.assertRaises(binascii.Error, base64.b32decode, b'MI023456')
+ self.assertRaises(ValueError, base64.b32decode, b'', map01=b'')
+ self.assertRaises(ValueError, base64.b32decode, b'', map01=b'LI')
+ self.assertRaises(TypeError, base64.b32decode, b'', map01=0)
+ eq(base64.b32decode(b'MLO23456', map01=None), res_L)
+ self.assertRaises(binascii.Error, base64.b32decode, b'M1023456',
map01=None)
data = b'M1023456'
data_str = data.decode('ascii')
diff --git
a/Misc/NEWS.d/next/Library/2026-04-06-11-20-24.gh-issue-148153.ZtsuTl.rst
b/Misc/NEWS.d/next/Library/2026-04-06-11-20-24.gh-issue-148153.ZtsuTl.rst
new file mode 100644
index 00000000000000..7fd30562739fee
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-04-06-11-20-24.gh-issue-148153.ZtsuTl.rst
@@ -0,0 +1,2 @@
+:func:`base64.b32encode` now always raises :exc:`ValueError` instead of
+:exc:`AssertionError` for the value of *map01* with invalid length.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]