Skip to content

Commit

Permalink
[issue-788] fix tag-value parser to allow NONE and NOASSERTION for pa…
Browse files Browse the repository at this point in the history
…ckage source info as they are valid strings

Signed-off-by: Meret Behrens <meret.behrens@tngtech.com>

# fixes 788
  • Loading branch information
meretp committed Aug 2, 2024
1 parent 552940a commit d761116
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/spdx_tools/spdx/parser/tagvalue/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def p_current_element_error(self, p):
"file_comment : FILE_COMMENT text_or_line\n "
"file_license_concluded : FILE_LICENSE_CONCLUDED license_or_no_assertion_or_none\n "
"package_name : PKG_NAME LINE\n description : PKG_DESCRIPTION text_or_line\n "
"summary : PKG_SUMMARY text_or_line\n source_info : PKG_SOURCE_INFO text_or_line\n "
"summary : PKG_SUMMARY text_or_line\n source_info : PKG_SOURCE_INFO text_or_line_including_no_assertion\n "
"homepage : PKG_HOMEPAGE line_or_no_assertion_or_none\n "
"download_location : PKG_DOWNLOAD_LOCATION line_or_no_assertion_or_none\n "
"originator : PKG_ORIGINATOR actor_or_no_assertion\n supplier : PKG_SUPPLIER actor_or_no_assertion\n "
Expand Down Expand Up @@ -216,7 +216,10 @@ def p_unknown_tag(self, p):
def p_text(self, p):
p[0] = str_from_text(p[1])

@grammar_rule("text_or_line : LINE\n line_or_no_assertion : LINE\nline_or_no_assertion_or_none : text_or_line")
@grammar_rule(
"text_or_line : LINE\n line_or_no_assertion : LINE\nline_or_no_assertion_or_none : text_or_line\n"
"text_or_line_including_no_assertion : text_or_line\ntext_or_line_including_no_assertion : NO_ASSERTION\n"
"text_or_line_including_no_assertion : NONE")
def p_line(self, p):
p[0] = p[1]

Expand Down
20 changes: 20 additions & 0 deletions tests/spdx/parser/tagvalue/test_package_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ def test_parse_package():
assert package.valid_until_date == datetime(2022, 1, 1, 12)


def test_parse_package_with_no_assertion_as_source_info():
parser = Parser()
package_str = "\n".join(
[
"PackageName: Test",
"SPDXID: SPDXRef-Package",
"PackageDownloadLocation: http://example.com/test",
"FilesAnalyzed: true",
"PackageSummary: <text>Test package</text>",
"PackageSourceInfo: NOASSERTION",
]
)
document = parser.parse("\n".join([DOCUMENT_STR, package_str]))
assert document is not None
package = document.packages[0]
assert package.name == "Test"
assert package.spdx_id == "SPDXRef-Package"
assert package.source_info == "NOASSERTION"


@pytest.mark.parametrize(
"package_str, expected_message",
[
Expand Down

0 comments on commit d761116

Please sign in to comment.