Skip to content

Commit d3c608f

Browse files
devesh-2002terriko
andauthored
fix: make _validate_xml actuall return a bool in all cases
Co-authored-by: Terri Oda <[email protected]>
1 parent d81ca11 commit d3c608f

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

cve_bin_tool/validator.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Copyright (C) 2022 Anthony Harrison
22
# SPDX-License-Identifier: GPL-3.0-or-later
3-
43
import logging
54
from pathlib import Path
65

@@ -13,8 +12,9 @@
1312

1413

1514
def _validate_xml(filename, xsd_file):
16-
# Resolve folder where schemas are present
1715
"""
16+
Validates an XML file against a specified XSD schema.
17+
1818
The XSD schema file contains the 'grammar rules' that the XML file should follow.
1919
It first constructs the path to the XSD schema file, then it creates an XMLSchema object using the xmlschema library.
2020
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):
2929
Returns:
3030
bool: True if the XML file is valid according to the schema, False otherwise.
3131
"""
32-
32+
# Resolve the folder where schemas are located.
3333
schemas_file = Path(__file__).resolve().parent / "schemas" / xsd_file
3434
the_schema = xmlschema.XMLSchema(Path(schemas_file))
3535

36-
LOGGER.debug(f"Validate {filename} against the_schema in {schemas_file}")
36+
LOGGER.debug(f"Validating {filename} against the schema in {schemas_file}")
3737
try:
3838
result = the_schema.validate(filename)
3939
except Exception as e:
4040
LOGGER.debug(f"Failed to validate {filename} against {xsd_file}. Exception {e}")
41-
result = "Fail"
41+
result = False
4242
return result is None
4343

4444

@@ -54,7 +54,6 @@ def validate_spdx(filename):
5454
Returns:
5555
bool: True if the SPDX file is valid according to the schema, False otherwise.
5656
"""
57-
5857
SPDX_SCHEMA = "spdx.xsd"
5958
return _validate_xml(filename, SPDX_SCHEMA)
6059

0 commit comments

Comments
 (0)