Skip to content

fix: keep deprecated altchars handling when decoding with padded=False - #1075

Merged
mayeut merged 1 commit into
mayeut:masterfrom
Shaisolaris:fix-validate-unpadded-altchars
Oct 14, 2026
Merged

mayeut merged 1 commit into
mayeut:masterfrom
Shaisolaris:fix-validate-unpadded-altchars

Conversation

@Shaisolaris

Copy link
Copy Markdown
Contributor

With validate=True and padded=False, the C extension rejects + or / in the input when custom altchars are given, while the pure Python fallback (and the Python 3.15 base64.b64decode it mirrors) still decode the data and emit the DeprecationWarning, because ignorechars was not specified:

import pybase64
pybase64.b64decode("+KKK", "-_", validate=True)                # b'\xf8\xa2\x8a' + DeprecationWarning
pybase64.b64decode("+KKK", "-_", validate=True, padded=False)  # binascii.Error: Non-base64 digit found

padded=False sets the internal ignorechars default, and that branch switched to the strict translate function. This change only switches to strict translation when the caller passed ignorechars, so an explicit ignorechars keeps raising as before (test_altchars_translation is unchanged).

Tests: added test_warning_data_dec_unpadded, the padded=False variant of test_warning_data_dec, including the 16 KiB slice case. Locally (Linux x86_64, Python 3.12, C extension built with all SIMD paths available up to AVX512VBMI):

  • before: 14 of the 28 new cases fail (the C validate=True ones); the full tests directory gives 14 failed, 22088 passed, 58 skipped
  • after: 22102 passed, 58 skipped

I did not run the sanitizer build, other platforms or Python 3.15. I left the changelog in the README alone in case you prefer to write that entry.

With validate=True and padded=False, the C extension used the strict
alphabet translation, so '+' or '/' with custom altchars raised
binascii.Error instead of the DeprecationWarning that the fallback and
the standard library give when ignorechars is not specified.
@codspeed

codspeed Bot commented Oct 12, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 48 untouched benchmarks


Comparing Shaisolaris:fix-validate-unpadded-altchars (5f07b89) with master (4d37a46)

Open in CodSpeed

@codecov

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.58%. Comparing base (4d37a46) to head (5f07b89).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1075   +/-   ##
=======================================
  Coverage   99.58%   99.58%           
=======================================
  Files          11       11           
  Lines        1937     1950   +13     
  Branches      306      307    +1     
=======================================
+ Hits         1929     1942   +13     
  Partials        8        8           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mayeut

mayeut commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR.
I'm a bit curious: how did you come across this issue ? just a test case downstream or from a real use case ?

@mayeut
mayeut merged commit 69287e2 into mayeut:master Oct 14, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants