Skip to content

fix(hashes): compute Adler-32 over UTF-8 bytes - #15733

Closed
HartD92 wants to merge 1 commit into
TheAlgorithms:masterfrom
DavidHart1:fix/adler32-utf8-15635
Closed

HartD92 wants to merge 1 commit into
TheAlgorithms:masterfrom
DavidHart1:fix/adler32-utf8-15635

Conversation

@HartD92

@HartD92 HartD92 commented Nov 12, 2026

Copy link
Copy Markdown

Describe your change

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Fixes #15635.

Compute Adler-32 over UTF-8 bytes rather than Unicode code points. Preserve the existing string API, ASCII checksums, and strict encoding errors. Update the function docstring to explain this behavior.

Only one algorithm file is changed. Existing doctests remain unchanged; additional regression doctests are deferred to a separate test-only contribution.

This PR targets this fork only, not upstream.

Validation

Package downloads used the Microsoft Python feed through session-only environment variables; repository configuration was not changed.

Command/check Result
python -m doctest -v .\hashes\adler32.py Passed: 2 doctests
uvx pytest .\hashes\adler32.py --doctest-modules Passed on Python 3.11
uvx --python 3.15t pytest .\hashes\adler32.py --doctest-modules Passed on Python 3.15t
uvx ruff check .\hashes\adler32.py Passed
uvx ruff format --check .\hashes\adler32.py Passed
uvx ty check .\hashes\adler32.py Passed
uvx pre-commit run --all-files All hooks passed except uv-lock, blocked by a feed-side 404 for fonttools metadata
Inline Python reference comparisons 1,014 inputs matched zlib.adler32(text.encode("utf-8")); 3 invalid-surrogate cases correctly raised UnicodeEncodeError

Reference comparisons covered empty text, ASCII, accented Latin, Japanese, emoji, embedded NULs, combining characters, long inputs, and deterministic random Unicode. The full repository pytest suite was not run.

Checklist

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues, then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

Preserve the text API while checksumming encoded bytes rather than Unicode code points. Document UTF-8 encoding and strict encoding errors without changing doctests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@HartD92 HartD92 closed this Nov 12, 2026
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.

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

1 participant