Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/spdx_tools/spdx/parser/tagvalue/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,14 @@ def p_pkg_files_analyzed(self, p):
if "files_analyzed" in self.current_element:
self.current_element["logger"].append(f"Multiple values for {p[1]} found. Line: {p.lineno(1)}")
return
self.current_element["files_analyzed"] = p[2] in ["true", "True"]
if p[2] == "true":
self.current_element["files_analyzed"] = True
elif p[2] == "false":
self.current_element["files_analyzed"] = False
else:
self.current_element["logger"].append(
f'The value of FilesAnalyzed must be either "true" or "false", but is: {p[2]}'
)

@grammar_rule("primary_package_purpose : PRIMARY_PACKAGE_PURPOSE LINE")
def p_primary_package_purpose(self, p):
Expand Down
2 changes: 1 addition & 1 deletion src/spdx_tools/spdx/writer/tagvalue/package_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def write_package(package: Package, text_output: TextIO):
write_actor("PackageOriginator", package.originator, text_output)
write_value("PackageDownloadLocation", package.download_location, text_output)

write_value("FilesAnalyzed", package.files_analyzed, text_output)
write_value("FilesAnalyzed", str(package.files_analyzed).lower(), text_output)
if package.verification_code:
package_verification_code = get_package_verification_code_string(package.verification_code)
write_value("PackageVerificationCode", package_verification_code, text_output)
Expand Down
8 changes: 7 additions & 1 deletion tests/spdx/parser/tagvalue/test_package_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_parse_package():
"SPDXID: SPDXRef-Package",
"PackageVersion: 1:22.36.1-8+deb11u1",
"PackageDownloadLocation: http://example.com/test",
"FilesAnalyzed: True",
"FilesAnalyzed: true",
"PackageSummary: <text>Test package</text>",
"PackageSourceInfo: <text>Version 1.0 of test</text>",
"PackageFileName: test-1.0.zip",
Expand Down Expand Up @@ -123,6 +123,12 @@ def test_parse_package():
"match specified grammar rule. Line: 2', 'Error while parsing "
"ValidUntilDate: Token did not match specified grammar rule. Line: 3']",
),
(
f"SPDXID:{DOCUMENT_SPDX_ID}\nPackageName: TestPackage\nSPDXID:SPDXRef-Package\n"
"PackageDownloadLocation: download.com\nFilesAnalyzed: FALSE",
"Error while parsing Package: "
'[\'The value of FilesAnalyzed must be either "true" or "false", but is: FALSE\']',
),
],
)
def test_parse_invalid_package(package_str, expected_message):
Expand Down
2 changes: 1 addition & 1 deletion tests/spdx/writer/tagvalue/test_package_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_package_writer():
call(f"PackageSupplier: Person: {package.supplier.name} ({package.supplier.email})\n"),
call(f"PackageOriginator: Person: {package.originator.name} ({package.originator.email})\n"),
call(f"PackageDownloadLocation: {package.download_location}\n"),
call("FilesAnalyzed: True\n"),
call("FilesAnalyzed: true\n"),
call(f"PackageVerificationCode: {package.verification_code.value} (excludes: ./exclude.py)\n"),
call("PackageChecksum: SHA1: 71c4025dd9897b364f3ebbb42c484ff43d00791c\n"),
call(f"PackageHomePage: {package.homepage}\n"),
Expand Down
8 changes: 4 additions & 4 deletions tests/spdx/writer/tagvalue/test_tagvalue_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_correct_order_of_elements():
call("PackageName: Test Package A\n"),
call("SPDXID: SPDXRef-Package-A\n"),
call("PackageDownloadLocation: \n"),
call("FilesAnalyzed: True\n"),
call("FilesAnalyzed: true\n"),
call("\n"),
call("## File Information\n"),
call("FileName: Test File B\n"),
Expand All @@ -130,7 +130,7 @@ def test_correct_order_of_elements():
call("PackageName: Test Package B\n"),
call("SPDXID: SPDXRef-Package-B\n"),
call("PackageDownloadLocation: \n"),
call("FilesAnalyzed: True\n"),
call("FilesAnalyzed: true\n"),
call("\n"),
call("\n"),
]
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_same_file_in_multiple_packages():
call("PackageName: Example package A\n"),
call("SPDXID: SPDXRef-Package-A\n"),
call("PackageDownloadLocation: https://download.com\n"),
call("FilesAnalyzed: True\n"),
call("FilesAnalyzed: true\n"),
call("\n"),
call("## File Information\n"),
call("FileName: Example file\n"),
Expand All @@ -210,7 +210,7 @@ def test_same_file_in_multiple_packages():
call("PackageName: Example package B\n"),
call("SPDXID: SPDXRef-Package-B\n"),
call("PackageDownloadLocation: https://download.com\n"),
call("FilesAnalyzed: True\n"),
call("FilesAnalyzed: true\n"),
call("\n"),
call("## Relationships\n"),
call("Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-Package-A\n"),
Expand Down