Skip to content

Reject trailing characters in hashes and encoded values - #486

Open
xiehuanyi wants to merge 1 commit into
python-validators:masterfrom
xiehuanyi:fix/complete-hash-encoding-matches-20261008
Open

xiehuanyi wants to merge 1 commit into
python-validators:masterfrom
xiehuanyi:fix/complete-hash-encoding-matches-20261008

Conversation

@xiehuanyi

Copy link
Copy Markdown

Hash and encoding validators accept a final newline because the $ regular expression anchor can match immediately before it. For example, sha256("a" * 64 + "\n") currently returns True, although the input contains a character outside the digest.

Use re.fullmatch() for the six digest validators and four encoding validators. This preserves the accepted alphabets, case handling, and padding rules while requiring the entire value to match. The regression tests cover trailing newlines, CRLF, spaces, and extra lines across all ten validators.

Validation: the new tests produced 10 failures on unmodified master; after the fix, all 935 tests pass. Ruff lint, formatting checks for the changed files, and the complete Pyright check pass with Python 3.14.6. No other interpreter versions were run locally.

Developed, reviewed, and tested with AI assistance.

Copilot AI balanced review requested due to automatic review settings October 8, 2026 10:52

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants