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: Handle multiline input for the Debian description field #119

Merged
merged 1 commit into from
Feb 18, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion deb/deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ Conflicts: {{join .}}
Homepage: {{.Info.Homepage}}
{{- end }}
{{- /* Mandatory fields */}}
Description: {{.Info.Description}}
Description: {{multiline .Info.Description}}
`

type controlData struct {
Expand All @@ -394,6 +394,10 @@ func writeControl(w io.Writer, data controlData) error {
"join": func(strs []string) string {
return strings.Trim(strings.Join(strs, ", "), " ")
},
"multiline": func(strs string) string {
ret := strings.ReplaceAll(strs, "\n", "\n ")
return strings.Trim(ret, " \n")
},
})
return template.Must(tmpl.Parse(controlTemplate)).Execute(w, data)
}
21 changes: 21 additions & 0 deletions deb/deb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,24 @@ func TestDebRules(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, string(bts), w.String())
}

func TestMultilineFields(t *testing.T) {
var w bytes.Buffer
assert.NoError(t, writeControl(&w, controlData{
Info: nfpm.WithDefaults(&nfpm.Info{
Name: "multiline",
Arch: "riscv64",
Description: "This field is a\nmultiline field\nthat should work.",
Priority: "extra",
Version: "1.0.0",
Section: "default",
}),
}))
var golden = "testdata/multiline.golden"
if *update {
require.NoError(t, ioutil.WriteFile(golden, w.Bytes(), 0655))
}
bts, err := ioutil.ReadFile(golden) //nolint:gosec
assert.NoError(t, err)
assert.Equal(t, string(bts), w.String())
}
9 changes: 9 additions & 0 deletions deb/testdata/multiline.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Package: multiline
Version: 1.0.0
Section: default
Priority: extra
Architecture: riscv64
Installed-Size: 0
Description: This field is a
multiline field
that should work.