aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Winslow <steve@swinslow.net>2021-05-02 17:28:35 -0400
committerGitHub <noreply@github.com>2021-05-02 17:28:35 -0400
commitcb47219353548d6fdb55034422dc4e7fbee19058 (patch)
treec0235f2a0cadd18a358883cf48a02712b3fc1bdd
parent2d832aee40b755130804757f02fa1d1f0921b8c8 (diff)
parent4cd473b27ea6d369b641282c6ec7d67911d3e96d (diff)
downloadspdx-tools-cb47219353548d6fdb55034422dc4e7fbee19058.tar.gz
Merge pull request #58 from bisakhmondal/fix_snippet
Fix for wrapping multiline snippet copyright in tvsaver
-rw-r--r--.gitignore1
-rw-r--r--tvsaver/saver2v1/save_snippet.go2
-rw-r--r--tvsaver/saver2v1/save_snippet_test.go35
-rw-r--r--tvsaver/saver2v2/save_snippet.go2
-rw-r--r--tvsaver/saver2v2/save_snippet_test.go35
5 files changed, 73 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index a111f2d..38da0f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
.vscode
+.idea
.DS_Store
scratch/*
*.swp
diff --git a/tvsaver/saver2v1/save_snippet.go b/tvsaver/saver2v1/save_snippet.go
index e82bc5a..645f7f5 100644
--- a/tvsaver/saver2v1/save_snippet.go
+++ b/tvsaver/saver2v1/save_snippet.go
@@ -33,7 +33,7 @@ func renderSnippet2_1(sn *spdx.Snippet2_1, w io.Writer) error {
fmt.Fprintf(w, "SnippetLicenseComments: %s\n", textify(sn.SnippetLicenseComments))
}
if sn.SnippetCopyrightText != "" {
- fmt.Fprintf(w, "SnippetCopyrightText: %s\n", sn.SnippetCopyrightText)
+ fmt.Fprintf(w, "SnippetCopyrightText: %s\n", textify(sn.SnippetCopyrightText))
}
if sn.SnippetComment != "" {
fmt.Fprintf(w, "SnippetComment: %s\n", textify(sn.SnippetComment))
diff --git a/tvsaver/saver2v1/save_snippet_test.go b/tvsaver/saver2v1/save_snippet_test.go
index 88b39c9..536545d 100644
--- a/tvsaver/saver2v1/save_snippet_test.go
+++ b/tvsaver/saver2v1/save_snippet_test.go
@@ -90,3 +90,38 @@ SnippetCopyrightText: Copyright (c) John Doe 20x6
t.Errorf("Expected %v, got %v", want.String(), got.String())
}
}
+
+func TestSaver2_1SnippetWrapsCopyrightMultiline(t *testing.T) {
+ sn := &spdx.Snippet2_1{
+ SnippetSPDXIdentifier: spdx.ElementID("Snippet17"),
+ SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File292"),
+ SnippetByteRangeStart: 17,
+ SnippetByteRangeEnd: 209,
+ SnippetLicenseConcluded: "GPL-2.0-or-later",
+ SnippetCopyrightText: `Copyright (c) John Doe 20x6
+Copyright (c) John Doe 20x6`,
+ }
+
+ // what we want to get, as a buffer of bytes
+ want := bytes.NewBufferString(`SnippetSPDXIdentifier: SPDXRef-Snippet17
+SnippetFromFileSPDXID: SPDXRef-File292
+SnippetByteRange: 17:209
+SnippetLicenseConcluded: GPL-2.0-or-later
+SnippetCopyrightText: <text>Copyright (c) John Doe 20x6
+Copyright (c) John Doe 20x6</text>
+
+`)
+
+ // render as buffer of bytes
+ var got bytes.Buffer
+ err := renderSnippet2_1(sn, &got)
+ if err != nil {
+ t.Errorf("Expected nil error, got %v", err)
+ }
+
+ // check that they match
+ c := bytes.Compare(want.Bytes(), got.Bytes())
+ if c != 0 {
+ t.Errorf("Expected %v, got %v", want.String(), got.String())
+ }
+}
diff --git a/tvsaver/saver2v2/save_snippet.go b/tvsaver/saver2v2/save_snippet.go
index 5cf2f2a..a8ede6c 100644
--- a/tvsaver/saver2v2/save_snippet.go
+++ b/tvsaver/saver2v2/save_snippet.go
@@ -33,7 +33,7 @@ func renderSnippet2_2(sn *spdx.Snippet2_2, w io.Writer) error {
fmt.Fprintf(w, "SnippetLicenseComments: %s\n", textify(sn.SnippetLicenseComments))
}
if sn.SnippetCopyrightText != "" {
- fmt.Fprintf(w, "SnippetCopyrightText: %s\n", sn.SnippetCopyrightText)
+ fmt.Fprintf(w, "SnippetCopyrightText: %s\n", textify(sn.SnippetCopyrightText))
}
if sn.SnippetComment != "" {
fmt.Fprintf(w, "SnippetComment: %s\n", textify(sn.SnippetComment))
diff --git a/tvsaver/saver2v2/save_snippet_test.go b/tvsaver/saver2v2/save_snippet_test.go
index 72378b4..c4b16bd 100644
--- a/tvsaver/saver2v2/save_snippet_test.go
+++ b/tvsaver/saver2v2/save_snippet_test.go
@@ -92,3 +92,38 @@ SnippetCopyrightText: Copyright (c) John Doe 20x6
t.Errorf("Expected %v, got %v", want.String(), got.String())
}
}
+
+func TestSaver2_2SnippetWrapsCopyrightMultiline(t *testing.T) {
+ sn := &spdx.Snippet2_2{
+ SnippetSPDXIdentifier: spdx.ElementID("Snippet17"),
+ SnippetFromFileSPDXIdentifier: spdx.MakeDocElementID("", "File292"),
+ SnippetByteRangeStart: 17,
+ SnippetByteRangeEnd: 209,
+ SnippetLicenseConcluded: "GPL-2.0-or-later",
+ SnippetCopyrightText: `Copyright (c) John Doe 20x6
+Copyright (c) John Doe 20x6`,
+ }
+
+ // what we want to get, as a buffer of bytes
+ want := bytes.NewBufferString(`SnippetSPDXIdentifier: SPDXRef-Snippet17
+SnippetFromFileSPDXID: SPDXRef-File292
+SnippetByteRange: 17:209
+SnippetLicenseConcluded: GPL-2.0-or-later
+SnippetCopyrightText: <text>Copyright (c) John Doe 20x6
+Copyright (c) John Doe 20x6</text>
+
+`)
+
+ // render as buffer of bytes
+ var got bytes.Buffer
+ err := renderSnippet2_2(sn, &got)
+ if err != nil {
+ t.Errorf("Expected nil error, got %v", err)
+ }
+
+ // check that they match
+ c := bytes.Compare(want.Bytes(), got.Bytes())
+ if c != 0 {
+ t.Errorf("Expected %v, got %v", want.String(), got.String())
+ }
+}