Skip to content

gh-144001: Add ignorechars parameter to Base64 decoder#144009

Closed
moneebullah25 wants to merge 6 commits intopython:mainfrom
moneebullah25:gh-144001-add-ignorechars-base64
Closed

gh-144001: Add ignorechars parameter to Base64 decoder#144009
moneebullah25 wants to merge 6 commits intopython:mainfrom
moneebullah25:gh-144001-add-ignorechars-base64

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

@picnixz
Copy link
Member

picnixz commented Jan 24, 2026

Closing since we will likely prefer Serhiy's PR for that. Thanks for the suggestion.

@picnixz picnixz closed this Jan 24, 2026
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

2 participants