Skip to content

pypi: check isinstance(lic, dict) before 'text' lookup in get_declared_license - #5567

Open
loveyadav1015 wants to merge 2 commits into
aboutcode-org:developfrom
loveyadav1015:fix-pypi-declared-license-text
Open

loveyadav1015 wants to merge 2 commits into
aboutcode-org:developfrom
loveyadav1015:fix-pypi-declared-license-text

Conversation

@loveyadav1015

Copy link
Copy Markdown

Fixes #5566

Summary

In get_declared_license() (src/packagedcode/pypi.py), if 'text' in lic: was checked without guarding that lic is a dict. When a Python package manifest (pyproject.toml, PKG-INFO, or *.dist-info/METADATA) declares license as a plain string containing the substring "text" (for example, "See license text in LICENSE"), 'text' in lic evaluates to True as a substring check and lic.get('text') raises AttributeError: 'str' object has no attribute 'get'. Because recognize.py catches Exception, the manifest is silently dropped with no package detected and no error reported.

Changes

  • Guard 'text' in lic with isinstance(lic, dict) in src/packagedcode/pypi.py (matching the existing isinstance(lic, dict) check for 'file').
  • Add regression tests in tests/packagedcode/test_pypi.py:
    • test_parse_pyproject_toml_license_string_containing_text
    • test_get_declared_license_string_containing_text
  • Add contributor entry (- Love Yadav @loveyadav1015) to AUTHORS.rst.

Verification

  • venv/bin/pytest tests/packagedcode/test_pypi.py: 187 passed
  • venv/bin/pytest tests/packagedcode/test_recognize.py: 32 passed
  • venv/bin/scancode --package --json - pyproject.toml on a minimal pyproject.toml with license = "See license text in LICENSE" now detects [email protected] (purl: pkg:pypi/[email protected]) and extracts extracted_license_statement: "license: See license text in LICENSE\n".

Tasks

  • Reviewed contribution guidelines
  • PR is descriptively titled 📑 and links the original issue above 🔗
  • Tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR
    Run tests locally to check for errors.
  • Commits are in uniquely-named feature branch and has no merge conflicts 📁
  • Updated documentation pages (if applicable)
  • Updated CHANGELOG.rst (if applicable)

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

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.

pypi: manifest silently dropped when license string contains "text"

1 participant