Repository navigation
pypi: check isinstance(lic, dict) before 'text' lookup in get_declared_license - #5567
Open
loveyadav1015 wants to merge 2 commits into
Open
loveyadav1015 wants to merge 2 commits into
loveyadav1015 wants to merge 2 commits into
Conversation
Guard the 'text' key check in get_declared_license() with isinstance(lic, dict) so plain license strings containing the substring 'text' do not raise AttributeError when calling .get('text').
Signed-off-by: Love Yadav <[email protected]>
…ate AUTHORS.rst Add regression tests for PyprojectTomlHandler.parse() and get_declared_license() when the declared license string contains 'text', and add contributor entry to AUTHORS.rst. Signed-off-by: Love Yadav <[email protected]>
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.
Fixes #5566
Summary
In
get_declared_license()(src/packagedcode/pypi.py),if 'text' in lic:was checked without guarding thatlicis adict. When a Python package manifest (pyproject.toml,PKG-INFO, or*.dist-info/METADATA) declareslicenseas a plain string containing the substring"text"(for example,"See license text in LICENSE"),'text' in licevaluates toTrueas a substring check andlic.get('text')raisesAttributeError: 'str' object has no attribute 'get'. Becauserecognize.pycatchesException, the manifest is silently dropped with no package detected and no error reported.Changes
'text' in licwithisinstance(lic, dict)insrc/packagedcode/pypi.py(matching the existingisinstance(lic, dict)check for'file').tests/packagedcode/test_pypi.py:test_parse_pyproject_toml_license_string_containing_texttest_get_declared_license_string_containing_text- Love Yadav @loveyadav1015) toAUTHORS.rst.Verification
venv/bin/pytest tests/packagedcode/test_pypi.py:187 passedvenv/bin/pytest tests/packagedcode/test_recognize.py:32 passedvenv/bin/scancode --package --json - pyproject.tomlon a minimalpyproject.tomlwithlicense = "See license text in LICENSE"now detects[email protected](purl: pkg:pypi/[email protected]) and extractsextracted_license_statement: "license: See license text in LICENSE\n".Tasks
Run tests locally to check for errors.