diff --git a/cve_bin_tool/validator.py b/cve_bin_tool/validator.py index 515aeb31f8..38ebe87a7c 100644 --- a/cve_bin_tool/validator.py +++ b/cve_bin_tool/validator.py @@ -1,6 +1,5 @@ # Copyright (C) 2022 Anthony Harrison # SPDX-License-Identifier: GPL-3.0-or-later - import logging from pathlib import Path @@ -13,8 +12,9 @@ def _validate_xml(filename, xsd_file): - # Resolve folder where schemas are present """ + Validates an XML file against a specified XSD schema. + The XSD schema file contains the 'grammar rules' that the XML file should follow. It first constructs the path to the XSD schema file, then it creates an XMLSchema object using the xmlschema library. It logs a debug message about the validation process, then attempts to validate the XML file against the schema. @@ -29,16 +29,16 @@ def _validate_xml(filename, xsd_file): Returns: bool: True if the XML file is valid according to the schema, False otherwise. """ - + # Resolve the folder where schemas are located. schemas_file = Path(__file__).resolve().parent / "schemas" / xsd_file the_schema = xmlschema.XMLSchema(Path(schemas_file)) - LOGGER.debug(f"Validate {filename} against the_schema in {schemas_file}") + LOGGER.debug(f"Validating {filename} against the schema in {schemas_file}") try: result = the_schema.validate(filename) except Exception as e: LOGGER.debug(f"Failed to validate {filename} against {xsd_file}. Exception {e}") - result = "Fail" + result = False return result is None @@ -54,7 +54,6 @@ def validate_spdx(filename): Returns: bool: True if the SPDX file is valid according to the schema, False otherwise. """ - SPDX_SCHEMA = "spdx.xsd" return _validate_xml(filename, SPDX_SCHEMA)