Skip to content

Commit

Permalink
fix: handle multiline input for the Debian description field (#119)
Browse files Browse the repository at this point in the history
The description field in the DEB control file supports multiline/verbatim
input. It is done by indenting the lines by two spaces. Before this patch,
the control file was broken if a user wanted to supply a multiline description.
  • Loading branch information
djboris9 committed Feb 18, 2020
1 parent 690f627 commit 4daa0df
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
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.

0 comments on commit 4daa0df

Please sign in to comment.