Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deb): blank line in package description #742

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.",
caarlos0 marked this conversation as resolved.
Show resolved Hide resolved
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.