Skip to content

fix: unhandled AttributeError on JSON and YAML lists in is_spdx_document - #2361

Merged
tdruez merged 2 commits into
aboutcode-org:mainfrom
Rucha0901:fix-is-spdx-document-attributeerror
Nov 23, 2026
Merged

tdruez merged 2 commits into
aboutcode-org:mainfrom
Rucha0901:fix-is-spdx-document-attributeerror

Conversation

@Rucha0901

Copy link
Copy Markdown
Contributor

Issues

Changes

  • In scanpipe/pipes/spdx.py, handle non-dict JSON and YAML content by checking isinstance(data, dict) inside with suppress(Exception): before checking for "SPDXID".
  • Support case-insensitive extension checking (.json, .yml, .yaml).
  • Add unit tests in scanpipe/tests/pipes/test_spdx.py for JSON/YAML lists, non-dict content, empty files, and case-insensitive extensions.

Checklist

  • I have read the contributing guidelines
  • I have linked an existing issue above
  • I have added unit tests covering the new code
  • I have reviewed and understood every line of this PR

@Jean-Regis-M Jean-Regis-M 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.

The isinstance(data, dict) guard fixes #2360 cleanly, and the tests cover the list and primitive cases well.

One concern about the case-insensitive extension part. It isn't reachable from the pipeline and doesn't match the loader:

  • The only caller, get_default_package_type in scanpipe/pipes/resolve.py (~line 510), only reaches is_spdx_document after a case-sensitive input_location.endswith((".json", ".xml", ".yml", ".yaml")). So test.JSON / test.YML never get here during a run.
  • If that gate were relaxed later, get_spdx_document_from_file (~line 454) still picks the parser with a case-sensitive .endswith((".yml", ".yaml")). A foo.YML SPDX doc would be detected as SPDX and then go through json.loads, ending in a confusing "SPDX document ... is not valid" error.

I'd either drop the .lower() change so this PR stays focused on the AttributeError, or apply the same case handling to those two spots in resolve.py (and cyclonedx.py:145/315 if consistency matters) with a test that goes through get_default_package_type.

Comment thread scanpipe/pipes/spdx.py
"""Return True if the file at `input_location` is a SPDX Document."""
input_location = str(input_location)
data = {}
location_lower = str(input_location).lower()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since #2360 explicitly asks for case-insensitive extensions, keeping this and making the two callers agree seems like the better of the two options I mentioned. Something like this in scanpipe/pipes/resolve.py:

# get_spdx_document_from_file (~L454)
if input_path.suffix.lower() in (".yml", ".yaml"):

# get_default_package_type (~L510)
if input_location.lower().endswith((".json", ".xml", ".yml", ".yaml")):

A test that calls resolve.get_default_package_type() with an uppercase .JSON SPDX file would then cover the real entry point and not only the helper.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Jean-Regis-M, thanks for the review and suggestions,

I have updated scanpipe/pipes/resolve.py so that both get_default_package_type() and get_spdx_document_from_file() handle extensions case-insensitively, agreeing with is_spdx_document().

I also added tests in scanpipe/tests/pipes/test_resolve.py covering uppercase .JSON and .YML SPDX files for both detection and parsing, and rebased the branch on latest main to resolve merge conflicts.

@Rucha0901
Rucha0901 force-pushed the fix-is-spdx-document-attributeerror branch from 761c059 to f1102db Compare November 22, 2026 16:38
@tdruez tdruez changed the title Fix unhandled AttributeError on JSON and YAML lists in is_spdx_document fix: unhandled AttributeError on JSON and YAML lists in is_spdx_document Nov 23, 2026
@tdruez
tdruez merged commit 6e34ff3 into aboutcode-org:main Nov 23, 2026
9 of 11 checks passed
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.

is_spdx_document raises unhandled AttributeError on JSON and YAML lists during SBOM resolution

3 participants