Skip to content

Very badly formed SPDX generates exceptions other than SPDXParsingError #831

Description

@king-doug-conti

The README says that when using parse_file() from parse_anything.py "Unsuccessful parsing will raise SPDXParsingError with a list of all encountered problems." However, other Exceptions can be raised for very badly formed files.

As an example, if the SPDX file is a valid JSON format, and there is a string where an array or object should be, it issues:

AttributeError: 'str' object has no attribute 'get'

In my test case, I took a valid spdx.json file, and replaced a package with a string value:

    # self.json_data is valid spdx in json format
    bad_spdx = json.loads(self.json_data)
    bad_spdx['packages'][0] = 'bad value'
    bad_spdx_json = json.dumps(bad_spdx) 

    with open("spdx.json", 'w') as f:
        f.write(bad_spdx_json)

    parse_file("spdx.json")

I would expect such a case to raise an SPDXParsingError with an indication like "packages[0] was expected to be an array, but was not"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions