diff options
author | Steve Winslow <steve@swinslow.net> | 2020-11-11 12:38:07 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-11 12:38:07 -0500 |
commit | 4ca6cd1fc37977db1969fcfdfa33dabbb2588010 (patch) | |
tree | 5d0d110da61267d40901c7172c8fb8e7f41bbf7d | |
parent | 4e07f1763686c4fc992cff2a18ff9ebd32ccd47f (diff) | |
parent | ae78e67710eece172cc8990ced41688777cf4e1e (diff) | |
download | spdx-tools-4ca6cd1fc37977db1969fcfdfa33dabbb2588010.tar.gz |
Merge pull request #43 from swinslow/issue-38
Fix tvloader storing incorrect doc ID
-rw-r--r-- | spdx/creation_info.go | 6 | ||||
-rw-r--r-- | tvloader/parser2v1/parse_creation_info.go | 6 | ||||
-rw-r--r-- | tvloader/parser2v1/parse_creation_info_test.go | 2 | ||||
-rw-r--r-- | tvloader/parser2v1/parser_test.go | 5 | ||||
-rw-r--r-- | tvloader/parser2v2/parse_creation_info.go | 6 | ||||
-rw-r--r-- | tvloader/parser2v2/parse_creation_info_test.go | 2 | ||||
-rw-r--r-- | tvloader/parser2v2/parser_test.go | 4 |
7 files changed, 20 insertions, 11 deletions
diff --git a/spdx/creation_info.go b/spdx/creation_info.go index a2b82b0..1bdaaab 100644 --- a/spdx/creation_info.go +++ b/spdx/creation_info.go @@ -14,7 +14,8 @@ type CreationInfo2_1 struct { // Cardinality: mandatory, one DataLicense string - // 2.3: SPDX Identifier; should be "SPDXRef-DOCUMENT" + // 2.3: SPDX Identifier; should be "DOCUMENT" to represent + // mandatory identifier of SPDXRef-DOCUMENT // Cardinality: mandatory, one SPDXIdentifier ElementID @@ -85,7 +86,8 @@ type CreationInfo2_2 struct { // Cardinality: mandatory, one DataLicense string - // 2.3: SPDX Identifier; should be "SPDXRef-DOCUMENT" + // 2.3: SPDX Identifier; should be "DOCUMENT" to represent + // mandatory identifier of SPDXRef-DOCUMENT // Cardinality: mandatory, one SPDXIdentifier ElementID diff --git a/tvloader/parser2v1/parse_creation_info.go b/tvloader/parser2v1/parse_creation_info.go index 44d1dfc..05130ee 100644 --- a/tvloader/parser2v1/parse_creation_info.go +++ b/tvloader/parser2v1/parse_creation_info.go @@ -29,7 +29,11 @@ func (parser *tvParser2_1) parsePairFromCreationInfo2_1(tag string, value string case "DataLicense": ci.DataLicense = value case "SPDXID": - ci.SPDXIdentifier = spdx.ElementID(value) + eID, err := extractElementID(value) + if err != nil { + return err + } + ci.SPDXIdentifier = eID case "DocumentName": ci.DocumentName = value case "DocumentNamespace": diff --git a/tvloader/parser2v1/parse_creation_info_test.go b/tvloader/parser2v1/parse_creation_info_test.go index c8741de..2a8c094 100644 --- a/tvloader/parser2v1/parse_creation_info_test.go +++ b/tvloader/parser2v1/parse_creation_info_test.go @@ -217,7 +217,7 @@ func TestParser2_1CanParseCreationInfoTags(t *testing.T) { if err != nil { t.Errorf("expected nil error, got %v", err) } - if parser.doc.CreationInfo.SPDXIdentifier != "SPDXRef-DOCUMENT" { + if parser.doc.CreationInfo.SPDXIdentifier != "DOCUMENT" { t.Errorf("got %v for SPDXIdentifier", parser.doc.CreationInfo.SPDXIdentifier) } diff --git a/tvloader/parser2v1/parser_test.go b/tvloader/parser2v1/parser_test.go index 543cb8f..4a61828 100644 --- a/tvloader/parser2v1/parser_test.go +++ b/tvloader/parser2v1/parser_test.go @@ -30,8 +30,8 @@ func TestParser2_1CanParseTagValues(t *testing.T) { if doc.CreationInfo.DataLicense != "CC0-1.0" { t.Errorf("expected DataLicense to be CC0-1.0, got %v", doc.CreationInfo.DataLicense) } - if doc.CreationInfo.SPDXIdentifier != "SPDXRef-DOCUMENT" { - t.Errorf("expected SPDXIdentifier to be SPDXRef-DOCUMENT, got %v", doc.CreationInfo.SPDXIdentifier) + if doc.CreationInfo.SPDXIdentifier != "DOCUMENT" { + t.Errorf("expected SPDXIdentifier to be DOCUMENT, got %v", doc.CreationInfo.SPDXIdentifier) } } @@ -77,4 +77,3 @@ func TestParser2_1StartFailsToParseIfInInvalidState(t *testing.T) { t.Errorf("expected non-nil error, got nil") } } - diff --git a/tvloader/parser2v2/parse_creation_info.go b/tvloader/parser2v2/parse_creation_info.go index e017c69..a3c7fbf 100644 --- a/tvloader/parser2v2/parse_creation_info.go +++ b/tvloader/parser2v2/parse_creation_info.go @@ -29,7 +29,11 @@ func (parser *tvParser2_2) parsePairFromCreationInfo2_2(tag string, value string case "DataLicense": ci.DataLicense = value case "SPDXID": - ci.SPDXIdentifier = spdx.ElementID(value) + eID, err := extractElementID(value) + if err != nil { + return err + } + ci.SPDXIdentifier = eID case "DocumentName": ci.DocumentName = value case "DocumentNamespace": diff --git a/tvloader/parser2v2/parse_creation_info_test.go b/tvloader/parser2v2/parse_creation_info_test.go index da29854..e12fc01 100644 --- a/tvloader/parser2v2/parse_creation_info_test.go +++ b/tvloader/parser2v2/parse_creation_info_test.go @@ -217,7 +217,7 @@ func TestParser2_2CanParseCreationInfoTags(t *testing.T) { if err != nil { t.Errorf("expected nil error, got %v", err) } - if parser.doc.CreationInfo.SPDXIdentifier != "SPDXRef-DOCUMENT" { + if parser.doc.CreationInfo.SPDXIdentifier != "DOCUMENT" { t.Errorf("got %v for SPDXIdentifier", parser.doc.CreationInfo.SPDXIdentifier) } diff --git a/tvloader/parser2v2/parser_test.go b/tvloader/parser2v2/parser_test.go index a2de032..7eec49c 100644 --- a/tvloader/parser2v2/parser_test.go +++ b/tvloader/parser2v2/parser_test.go @@ -30,8 +30,8 @@ func TestParser2_2CanParseTagValues(t *testing.T) { if doc.CreationInfo.DataLicense != "CC0-1.0" { t.Errorf("expected DataLicense to be CC0-1.0, got %v", doc.CreationInfo.DataLicense) } - if doc.CreationInfo.SPDXIdentifier != "SPDXRef-DOCUMENT" { - t.Errorf("expected SPDXIdentifier to be SPDXRef-DOCUMENT, got %v", doc.CreationInfo.SPDXIdentifier) + if doc.CreationInfo.SPDXIdentifier != "DOCUMENT" { + t.Errorf("expected SPDXIdentifier to be DOCUMENT, got %v", doc.CreationInfo.SPDXIdentifier) } } |