Skip to content
Merged
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
3 changes: 2 additions & 1 deletion Lib/base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ def b16decode(s, casefold=False, *, ignorechars=b''):
for b in b'abcdef':
if b in s and b not in ignorechars:
raise binascii.Error('Non-base16 digit found')
s = s.translate(None, delete=b'abcdef')
if ignorechars:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check the actual byte length before skipping translation

When ignorechars is a nonempty bytes subclass whose __bool__ returns false, this condition skips the translation even though the lowercase characters must be removed. For example, with such a subclass containing b'a', b16decode(b'aB', ignorechars=...) now decodes the lowercase a as a hex digit and returns b'\xab'; previously a was ignored and the remaining odd digit raised binascii.Error. Normalize bytes subclasses or otherwise test the underlying buffer's emptiness without invoking overridable truthiness.

AGENTS.md reference: AGENTS.md:L16-L16

Useful? React with 👍 / 👎.

s = s.translate(None, delete=b'abcdef')
return binascii.unhexlify(s, ignorechars=ignorechars)

#
Expand Down
Loading