Skip to content

Commit 3d3100a

Browse files
[issue-753] only allow lowercase values for FilesAnalyzed in tag-value
Signed-off-by: Armin Tänzer <armin.taenzer@tngtech.com>
1 parent b97cba3 commit 3d3100a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/spdx_tools/spdx/parser/tagvalue/parser.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,14 @@ def p_pkg_files_analyzed(self, p):
427427
if "files_analyzed" in self.current_element:
428428
self.current_element["logger"].append(f"Multiple values for {p[1]} found. Line: {p.lineno(1)}")
429429
return
430-
self.current_element["files_analyzed"] = p[2] in ["true", "True"]
430+
if p[2] == "true":
431+
self.current_element["files_analyzed"] = True
432+
elif p[2] == "false":
433+
self.current_element["files_analyzed"] = False
434+
else:
435+
self.current_element["logger"].append(
436+
f'The value of FilesAnalyzed must be either "true" or "false", but is: {p[2]}'
437+
)
431438

432439
@grammar_rule("primary_package_purpose : PRIMARY_PACKAGE_PURPOSE LINE")
433440
def p_primary_package_purpose(self, p):

tests/spdx/parser/tagvalue/test_package_parser.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_parse_package():
2222
"SPDXID: SPDXRef-Package",
2323
"PackageVersion: 1:22.36.1-8+deb11u1",
2424
"PackageDownloadLocation: http://example.com/test",
25-
"FilesAnalyzed: True",
25+
"FilesAnalyzed: true",
2626
"PackageSummary: <text>Test package</text>",
2727
"PackageSourceInfo: <text>Version 1.0 of test</text>",
2828
"PackageFileName: test-1.0.zip",
@@ -123,6 +123,12 @@ def test_parse_package():
123123
"match specified grammar rule. Line: 2', 'Error while parsing "
124124
"ValidUntilDate: Token did not match specified grammar rule. Line: 3']",
125125
),
126+
(
127+
f"SPDXID:{DOCUMENT_SPDX_ID}\nPackageName: TestPackage\nSPDXID:SPDXRef-Package\n"
128+
"PackageDownloadLocation: download.com\nFilesAnalyzed: FALSE",
129+
"Error while parsing Package: "
130+
'[\'The value of FilesAnalyzed must be either "true" or "false", but is: FALSE\']',
131+
),
126132
],
127133
)
128134
def test_parse_invalid_package(package_str, expected_message):

0 commit comments

Comments
 (0)