Skip to content

FIX: Ignore line breaks and spaces in Base64Decoder.write - #341

Open
prudhvi1709 wants to merge 1 commit into
Kludex:mainfrom
prudhvi1709:fix/base64-decoder-whitespace
Open

prudhvi1709 wants to merge 1 commit into
Kludex:mainfrom
prudhvi1709:fix/base64-decoder-whitespace

Conversation

@prudhvi1709

@prudhvi1709 prudhvi1709 commented Oct 18, 2026 •

Copy link
Copy Markdown

Fixes #340

Base64Decoder.write() sliced input to a multiple of 4 bytes while the data still contained \r, \n, space and tab. Line-wrapped base64 therefore failed with DecodeError whenever a quartet straddled a line break, and the outcome depended on chunk boundaries.

Changes

  • write() strips \r, \n, space and tab before counting and decoding. Other invalid bytes still raise DecodeError, as before.
  • write() now returns the number of bytes passed in. Previously it returned the length of the data after the internal cache was prepended, which does not match the docstring ("the length of the data to indicate no error").
  • Added test_line_wrapped_input_any_split: base64.encodebytes() output split at every offset must decode to the original bytes, and write() must return the input length.

Testing

uv run pytest gives 164 passed. The new test fails on main without the change.

View guided diff

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 2 files

View guided diff | Re-trigger cubic

@codspeed

codspeed Bot commented Oct 18, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 5 untouched benchmarks
⏩ 5 skipped benchmarks1


Comparing prudhvi1709:fix/base64-decoder-whitespace (3fd83b4) with main (51ff1a4)

Open in CodSpeed

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

This branch has not been deployed

No deployments
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.

Base64Decoder raises DecodeError on line-wrapped (MIME-style) base64

1 participant