Skip to content

Commit

Permalink
Fix wrapping of multiline FileCopyrightText (#9)
Browse files Browse the repository at this point in the history
Fixes #8

Signed-off-by: Steve Winslow <swinslow@gmail.com>
  • Loading branch information
swinslow committed Apr 16, 2019
1 parent 3dcceb5 commit 011a307
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion v0/tvsaver/saver2v1/save_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func renderFile2_1(f *spdx.File2_1, w io.Writer) error {
fmt.Fprintf(w, "LicenseComments: %s\n", f.LicenseComments)
}
if f.FileCopyrightText != "" {
fmt.Fprintf(w, "FileCopyrightText: %s\n", f.FileCopyrightText)
fmt.Fprintf(w, "FileCopyrightText: %s\n", textify(f.FileCopyrightText))
}
for _, aop := range f.ArtifactOfProjects {
fmt.Fprintf(w, "ArtifactOfProjectName: %s\n", aop.Name)
Expand Down
38 changes: 38 additions & 0 deletions v0/tvsaver/saver2v1/save_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,41 @@ FileCopyrightText: Copyright (c) Jane Doe
t.Errorf("Expected %v, got %v", want.String(), got.String())
}
}

func TestSaver2_1FileWrapsCopyrightMultiLine(t *testing.T) {
f := &spdx.File2_1{
FileName: "/tmp/whatever.txt",
FileSPDXIdentifier: "SPDXRef-File123",
FileChecksumSHA1: "85ed0817af83a24ad8da68c2b5094de69833983c",
LicenseConcluded: "Apache-2.0",
LicenseInfoInFile: []string{
"Apache-2.0",
},
FileCopyrightText: `Copyright (c) Jane Doe
Copyright (c) John Doe`,
}

// what we want to get, as a buffer of bytes
want := bytes.NewBufferString(`FileName: /tmp/whatever.txt
SPDXID: SPDXRef-File123
FileChecksum: SHA1: 85ed0817af83a24ad8da68c2b5094de69833983c
LicenseConcluded: Apache-2.0
LicenseInfoInFile: Apache-2.0
FileCopyrightText: <text>Copyright (c) Jane Doe
Copyright (c) John Doe</text>
`)

// render as buffer of bytes
var got bytes.Buffer
err := renderFile2_1(f, &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())
}
}

0 comments on commit 011a307

Please sign in to comment.