tools-python
tools-python copied to clipboard
Very badly formed SPDX generates exceptions other than SPDXParsingError
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"