Repository navigation
fix(contrib): raise UnknownHashTypeException instead of AttributeError/IndexError from from_composite_str() - #1091
Open
biggdawg320 wants to merge 1 commit into
Conversation
…fixes HashTypeFactory.from_composite_str() raised uncaught AttributeError for unsupported sha*/sha3*/blake2* prefixes (e.g. 'sha224', 'blake2b_256') and IndexError when the composite string was missing the ':' separator (e.g. 'md5'), instead of the documented UnknownHashTypeException. Guard the getattr() lookups with a default of None and check the split result length before raising the documented exception, matching the behavior of from_hashlib_alg(). Co-Authored-By: Claude <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
HashTypeFactory.from_composite_str()is documented to raiseUnknownHashTypeExceptionwhen the hash type cannot be determined, but it instead raised uncaughtAttributeErrorfor unsupportedsha*/sha3*/blake2*prefixes (e.g. PyPI'sblake2b_256wheel digest key or PEP 691'ssha224), andIndexErrorwhen the composite string was missing the:separator (e.g.'md5'). This could allow the error to escapeexcept UnknownHashTypeExceptionhandlers in downstream consumers such ascyclonedx-python'srequirements.py,pipenv.py, andpoetry.py.This change makes
from_composite_str()consistently raiseUnknownHashTypeExceptionfor all unrecognized inputs, matching its docstring and the existing behavior offrom_hashlib_alg().Resolves or fixes issue: #1075
Testing
Added
tests/test_contrib/test_hash_factories.pycovering:blake2suffix (blake2b_256:...)shasuffix (sha224:...):separator (md5)Verified these tests fail with
AttributeError/IndexErroragainst the original code and pass after the fix, and that the fulltests/test_contribsuite still passes.AI Tool Disclosure
HashTypeFactory.from_composite_str()raises AttributeError / IndexError instead of UnknownHashTypeException #1075 with a failing test, then fixHashTypeFactory.from_composite_str()so unsupported hash prefixes and missing:separators raiseUnknownHashTypeExceptioninstead ofAttributeError/IndexError.Affirmation
Fixes #1075
This change was drafted with AI assistance (Claude) and verified against the project's own test suite before submission.