Skip to content

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

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

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

Conversation

@moneebullah25

@moneebullah25moneebullah25 commented Jan 18, 2026

Copy link
Copy Markdown
Contributor

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 charsbase64.b64decode(b'YWJj\n', ignorechars=b'\n') # OK: b'abc'base64.b64decode(b'YWJj!', ignorechars=b'\n') # Error# Strict: reject all non-base64base64.b64decode(b'YWJj\n', ignorechars=b'') # Error# Default behavior unchangedbase64.b64decode(b'YWJj\n') # OK: b'abc' (ignores all)

Closes#144001

@picnixz

Copy link
Copy Markdown
Member

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

@picnixzpicnixz closed this Jan 24, 2026
Sign up for freeto 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

@moneebullah25@picnixz