G
YouTube TikTok Games
Skip to content

fix: adler32 accepts bytes input instead of str - #15721

Open
dbdefault wants to merge 1 commit into
TheAlgorithms:masterfrom
dbdefault:fix/15635/adler32-bytes
Open

dbdefault wants to merge 1 commit into
TheAlgorithms:masterfrom
dbdefault:fix/15635/adler32-bytes

Conversation

@dbdefault

Copy link
Copy Markdown

Fixes #15635

Describe your change

  • hashes/adler32.py: accept bytes input instead of str, iterating over raw byte values rather than Unicode code points
  • This makes output match zlib.adler32(data.encode()) for all inputs, including non-ASCII text
  • Add TypeError for non-bytes input (consistent with hashes/crc32.py)
  • Add doctests comparing against zlib.adler32 for ASCII, non-ASCII, and empty inputs

Checklist

  • I have read the contributing guidelines
  • I have run ruff check and ruff format on my changes
  • I have added doctests for any new or changed functions
  • My change is one algorithm file

Fixes #15635

Accept bytes input instead of str, iterating over raw byte values rather
than Unicode code points. This makes output match zlib.adler32 for all
inputs including non-ASCII text. Add TypeError for non-bytes input
(consistent with hashes/crc32.py). Add doctests comparing against
zlib.adler32 for ASCII, non-ASCII, and empty inputs.

Fixes TheAlgorithms#15635

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

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hashes/adler32.py: checksum diverges from the Adler-32 spec for any non-ASCII input (sums Unicode code points instead of bytes)

1 participant