Skip to content

Commit 1e3031c

Browse files
authored
Merge pull request #799 from meretp/fix-tv-parser-annotator
[issue-798] fix tag-value parser: parse Tool or Organization as annotator
2 parents 44d510e + 0e1c9ee commit 1e3031c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def p_snippet_range(self, p):
488488

489489
# parsing methods for annotation
490490

491-
@grammar_rule("annotator : ANNOTATOR PERSON_VALUE\n| TOOL_VALUE\n| ORGANIZATION_VALUE")
491+
@grammar_rule("annotator : ANNOTATOR PERSON_VALUE\n| ANNOTATOR TOOL_VALUE\n| ANNOTATOR ORGANIZATION_VALUE")
492492
def p_annotator(self, p):
493493
self.initialize_new_current_element(Annotation)
494494
set_value(p, self.current_element, method_to_apply=ActorParser.parse_actor)

tests/spdx/parser/tagvalue/test_annotation_parser.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ def test_parse_annotation():
3434
assert annotation.spdx_id == DOCUMENT_SPDX_ID
3535

3636

37+
def test_parse_annotation_with_organization_as_annotator():
38+
parser = Parser()
39+
annotation_str = "\n".join(
40+
[
41+
"Annotator: Organization: some-organization",
42+
"AnnotationDate: 2010-01-29T18:30:22Z",
43+
"AnnotationComment: <text>Document level annotation</text>",
44+
"AnnotationType: OTHER",
45+
f"SPDXREF: {DOCUMENT_SPDX_ID}",
46+
]
47+
)
48+
document = parser.parse("\n".join([DOCUMENT_STR, annotation_str]))
49+
assert document is not None
50+
assert len(document.annotations) == 1
51+
annotation = document.annotations[0]
52+
assert annotation.annotator.name == "some-organization"
53+
assert annotation.annotation_date == datetime(2010, 1, 29, 18, 30, 22)
54+
assert annotation.annotation_comment == "Document level annotation"
55+
assert annotation.annotation_type == AnnotationType.OTHER
56+
assert annotation.spdx_id == DOCUMENT_SPDX_ID
57+
58+
3759
@pytest.mark.parametrize(
3860
"annotation_str, expected_message",
3961
[

0 commit comments

Comments
 (0)