Skip to content

Commit aadb160

Browse files
committed
gh-155193: Add missing canonical parameter to urlsafe_b64decode()
The what's new entry for 3.15 documents canonical=False being added to b32decode(), b32hexdecode(), b64decode(), urlsafe_b64decode(), a85decode(), b85decode(), and z85decode() (gh-146311), but urlsafe_b64decode() did not actually receive the parameter. Add canonical=False to urlsafe_b64decode()'s signature and pass it through to binascii.a2b_base64(), consistent with b64decode(). The default preserves existing behavior.
1 parent 83b3354 commit aadb160

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Lib/base64.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def urlsafe_b64encode(s, *, padded=True):
164164
return binascii.b2a_base64(s, padded=padded, newline=False,
165165
alphabet=binascii.URLSAFE_BASE64_ALPHABET)
166166

167-
def urlsafe_b64decode(s, *, padded=False):
167+
def urlsafe_b64decode(s, *, padded=False, canonical=False):
168168
"""Decode bytes using the URL- and filesystem-safe Base64 alphabet.
169169
170170
Argument s is a bytes-like object or ASCII string to decode. The result
@@ -175,6 +175,9 @@ def urlsafe_b64decode(s, *, padded=False):
175175
176176
If padded is false, padding in input is not required.
177177
178+
If canonical is true, non-canonical encodings (non-zero padding bits or
179+
other non-canonical forms) are rejected.
180+
178181
The alphabet uses '-' instead of '+' and '_' instead of '/'.
179182
"""
180183
s = _bytes_from_decode_data(s)
@@ -184,7 +187,8 @@ def urlsafe_b64decode(s, *, padded=False):
184187
badchar = b
185188
break
186189
s = s.translate(_urlsafe_decode_translation)
187-
result = binascii.a2b_base64(s, strict_mode=False, padded=padded)
190+
result = binascii.a2b_base64(s, strict_mode=False, padded=padded,
191+
canonical=canonical)
188192
if badchar is not None:
189193
import warnings
190194
warnings.warn(f'invalid character {chr(badchar)!a} in URL-safe Base64 data '

0 commit comments

Comments
 (0)