fix: raise a clear error for an spdx_id with multiple colons - #902
Open
Atishyy27 wants to merge 1 commit into
Open
fix: raise a clear error for an spdx_id with multiple colons#902Atishyy27 wants to merge 1 commit into
Atishyy27 wants to merge 1 commit into
Conversation
get_full_element_spdx_id unpacked spdx_id.split(":") into exactly two
values, so an id containing more than one colon raised
"ValueError: too many values to unpack (expected 2)" during
bump_spdx_document. validate_spdx_id already rejects such ids with a
descriptive message, but the bump path can run without validation
(pyspdxtools3 --novalidation, or a direct library call).
Check the split length and raise the same descriptive error instead.
Fixes spdx#901
Signed-off-by: Atishyy27 <[email protected]>
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.
Fixes #901.
Problem
get_full_element_spdx_idunpackedelement.spdx_id.split(":")into exactly two values, so anspdx_idcontaining more than one colon raisedValueError: too many values to unpack (expected 2)duringbump_spdx_document.validate_spdx_idalready rejects such ids with a descriptive message, but the bump path can run without validation —pyspdxtools3 --novalidation, or any directbump_spdx_document()library call — so a malformed id from a third-party SBOM reaches this line and crashes with an internal unpack error.Change
Check the split length first and raise the same descriptive error the validator uses. Single-colon (external document ref) and no-colon ids are unaffected.
Testing
Added
test_bump_external_element_with_malformed_spdx_idintests/spdx3/bump/test_external_element_bump.py.too many values to unpack (expected 2).test_bump_external_elementsstill passes.black,isortandflake8are clean on both changed files.