Skip to content

Commit 3217883

Browse files
meretparmintaenzertng
authored andcommittedAug 23, 2024
[issue-788] fix tag-value parser to allow NONE and NOASSERTION for package source info as they are valid strings
Signed-off-by: Meret Behrens <meret.behrens@tngtech.com> # fixes 788
1 parent 40331ac commit 3217883

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed
 

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def p_current_element_error(self, p):
180180
"file_comment : FILE_COMMENT text_or_line\n "
181181
"file_license_concluded : FILE_LICENSE_CONCLUDED license_or_no_assertion_or_none\n "
182182
"package_name : PKG_NAME LINE\n description : PKG_DESCRIPTION text_or_line\n "
183-
"summary : PKG_SUMMARY text_or_line\n source_info : PKG_SOURCE_INFO text_or_line\n "
183+
"summary : PKG_SUMMARY text_or_line\n source_info : PKG_SOURCE_INFO text_or_line_including_no_assertion\n "
184184
"homepage : PKG_HOMEPAGE line_or_no_assertion_or_none\n "
185185
"download_location : PKG_DOWNLOAD_LOCATION line_or_no_assertion_or_none\n "
186186
"originator : PKG_ORIGINATOR actor_or_no_assertion\n supplier : PKG_SUPPLIER actor_or_no_assertion\n "
@@ -216,7 +216,11 @@ def p_unknown_tag(self, p):
216216
def p_text(self, p):
217217
p[0] = str_from_text(p[1])
218218

219-
@grammar_rule("text_or_line : LINE\n line_or_no_assertion : LINE\nline_or_no_assertion_or_none : text_or_line")
219+
@grammar_rule(
220+
"text_or_line : LINE\n line_or_no_assertion : LINE\nline_or_no_assertion_or_none : text_or_line\n"
221+
"text_or_line_including_no_assertion : text_or_line\ntext_or_line_including_no_assertion : NO_ASSERTION\n"
222+
"text_or_line_including_no_assertion : NONE"
223+
)
220224
def p_line(self, p):
221225
p[0] = p[1]
222226

‎tests/spdx/parser/tagvalue/test_package_parser.py

+20
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@ def test_parse_package():
8383
assert package.valid_until_date == datetime(2022, 1, 1, 12)
8484

8585

86+
def test_parse_package_with_no_assertion_as_source_info():
87+
parser = Parser()
88+
package_str = "\n".join(
89+
[
90+
"PackageName: Test",
91+
"SPDXID: SPDXRef-Package",
92+
"PackageDownloadLocation: http://example.com/test",
93+
"FilesAnalyzed: true",
94+
"PackageSummary: <text>Test package</text>",
95+
"PackageSourceInfo: NOASSERTION",
96+
]
97+
)
98+
document = parser.parse("\n".join([DOCUMENT_STR, package_str]))
99+
assert document is not None
100+
package = document.packages[0]
101+
assert package.name == "Test"
102+
assert package.spdx_id == "SPDXRef-Package"
103+
assert package.source_info == "NOASSERTION"
104+
105+
86106
@pytest.mark.parametrize(
87107
"package_str, expected_message",
88108
[

0 commit comments

Comments
 (0)
Please sign in to comment.