Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Lib/base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def urlsafe_b64encode(s, *, padded=True):
return binascii.b2a_base64(s, padded=padded, newline=False,
alphabet=binascii.URLSAFE_BASE64_ALPHABET)

def urlsafe_b64decode(s, *, padded=False):
def urlsafe_b64decode(s, *, padded=False, canonical=False):
"""Decode bytes using the URL- and filesystem-safe Base64 alphabet.

Argument s is a bytes-like object or ASCII string to decode. The result
Expand All @@ -175,6 +175,9 @@ def urlsafe_b64decode(s, *, padded=False):

If padded is false, padding in input is not required.

If canonical is true, non-canonical encodings (non-zero padding bits or
other non-canonical forms) are rejected.

The alphabet uses '-' instead of '+' and '_' instead of '/'.
"""
s = _bytes_from_decode_data(s)
Expand All @@ -184,7 +187,8 @@ def urlsafe_b64decode(s, *, padded=False):
badchar = b
break
s = s.translate(_urlsafe_decode_translation)
result = binascii.a2b_base64(s, strict_mode=False, padded=padded)
result = binascii.a2b_base64(s, strict_mode=False, padded=padded,
canonical=canonical)
if badchar is not None:
import warnings
warnings.warn(f'invalid character {chr(badchar)!a} in URL-safe Base64 data '
Expand Down
Loading