Repository: goreleaser/nfpm
Pull request #119 (2020-02-18 11:42:21)

fix: Handle multiline input for the Debian description field
Hi There

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.

Blank lines by using a full-stop-character are not implemented as it requires to convert the whole block to a 1-level intended block instead of the verbatim 2-level intended block.

Ref: [debian-policy](https://www.debian.org/doc/debian-policy/ch-controlfields.html#description)

codecov-io: # [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/119?src=pr&el=h1) Report
> Merging [#119](https://codecov.io/gh/goreleaser/nfpm/pull/119?src=pr&el=desc) into [master](https://codecov.io/gh/goreleaser/nfpm/commit/690f627895f13c761b5e5721099f44e691a91244?src=pr&el=desc) will **increase** coverage by `0.22%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/goreleaser/nfpm/pull/119/graphs/tree.svg?width=650&token=9QKGIxn7wg&height=150&src=pr)](https://codecov.io/gh/goreleaser/nfpm/pull/119?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #119      +/-   ##
==========================================
+ Coverage   71.34%   71.57%   +0.22%     
==========================================
  Files           5        5              
  Lines         499      503       +4     
==========================================
+ Hits          356      360       +4     
  Misses         90       90              
  Partials       53       53
```


| [Impacted Files](https://codecov.io/gh/goreleaser/nfpm/pull/119?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [deb/deb.go](https://codecov.io/gh/goreleaser/nfpm/pull/119/diff?src=pr&el=tree#diff-ZGViL2RlYi5nbw==) | `72.33% <100%> (+0.54%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/119?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/goreleaser/nfpm/pull/119?src=pr&el=footer). Last update [690f627...5c4451c](https://codecov.io/gh/goreleaser/nfpm/pull/119?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/deb/deb.go b/deb/deb.go
index 50d5829..dee3b4b 100644
--- a/deb/deb.go
+++ b/deb/deb.go
@@ -380,7 +380,7 @@ Conflicts: {{join .}}
 Homepage: {{.Info.Homepage}}
 {{- end }}
 {{- /* Mandatory fields */}}
-Description: {{.Info.Description}}
+Description: {{multiline .Info.Description}}
 `
 
 type controlData struct {
@@ -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)
 }


Test patch:
diff --git a/deb/deb_test.go b/deb/deb_test.go
index b54f04b..535bf1e 100644
--- a/deb/deb_test.go
+++ b/deb/deb_test.go
@@ -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())
+}
diff --git a/deb/testdata/multiline.golden b/deb/testdata/multiline.golden
new file mode 100644
index 0000000..4d29e36
--- /dev/null
+++ b/deb/testdata/multiline.golden
@@ -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.