Skip to content

Conversation

@moneebullah25
Copy link
Contributor

@moneebullah25 moneebullah25 commented Jan 18, 2026

Summary

  • Add the ignorechars parameter to binascii.a2b_base64() and base64.b64decode()
  • When provided, only characters in this set will be silently ignored during decoding
  • Other non-base64 characters will cause a binascii.Error
  • Similar to the existing ignorechars parameter in base64.a85decode()

This addresses the feature request in #144001 where the existing strict_mode/validate parameters are "all-or-nothing" - either all non-alphabet characters are rejected, or all are ignored. The new ignorechars parameter allows selective filtering (e.g., ignoring whitespace while rejecting other invalid characters).

API

# Ignore only whitespace, reject other invalid chars
base64.b64decode(b'YWJj\n', ignorechars=b'\n')  # OK: b'abc'
base64.b64decode(b'YWJj!', ignorechars=b'\n')   # Error

# Strict: reject all non-base64
base64.b64decode(b'YWJj\n', ignorechars=b'')    # Error

# Default behavior unchanged
base64.b64decode(b'YWJj\n')                      # OK: b'abc' (ignores all)

Closes #144001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the ignorechars parameter in the Base64 decoder

1 participant