Skip to content

Commit

Permalink
fix(deb): blank line in package description (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
abemedia authored Nov 25, 2023
1 parent ab3cda2 commit 3485ec3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
17 changes: 15 additions & 2 deletions deb/deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package deb

import (
"archive/tar"
"bufio"
"bytes"
"compress/gzip"
"crypto/md5" // nolint:gas
Expand Down Expand Up @@ -762,8 +763,20 @@ func writeControl(w io.Writer, data controlData) error {
return strings.Trim(strings.Join(strs, ", "), " ")
},
"multiline": func(strs string) string {
ret := strings.ReplaceAll(strs, "\n", "\n ")
return strings.Trim(ret, " \n")
var b strings.Builder
s := bufio.NewScanner(strings.NewReader(strings.TrimSpace(strs)))
s.Scan()
b.Write(bytes.TrimSpace(s.Bytes()))
for s.Scan() {
b.WriteString("\n ")
l := bytes.TrimSpace(s.Bytes())
if len(l) == 0 {
b.WriteByte('.')
} else {
b.Write(l)
}
}
return b.String()
},
"nonEmpty": func(strs []string) []string {
var result []string
Expand Down
2 changes: 1 addition & 1 deletion deb/deb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ func TestMultilineFields(t *testing.T) {
Info: nfpm.WithDefaults(&nfpm.Info{
Name: "multiline",
Arch: "riscv64",
Description: "This field is a\nmultiline field\nthat should work.",
Description: "This field is a\nmultiline field\n\nthat should work.",
Priority: "extra",
Version: "1.0.0",
Section: "default",
Expand Down
1 change: 1 addition & 0 deletions deb/testdata/multiline.golden
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Architecture: riscv64
Installed-Size: 0
Description: This field is a
multiline field
.
that should work.

0 comments on commit 3485ec3

Please sign in to comment.