Skip to content

Commit dea1a6c

Browse files
committed
Source files: fix empty line in Package-List
1 parent 2a6eeab commit dea1a6c

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

deb/format.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,11 @@ func (c *ControlFileReader) ReadStanza() (Stanza, error) {
288288
lastField = canonicalCase(parts[0])
289289
lastFieldMultiline = isMultilineField(lastField, c.isRelease)
290290
if lastFieldMultiline {
291-
stanza[lastField] = parts[1]
292-
if parts[1] != "" {
291+
// Trim trailing whitespace from the inline value so that
292+
// "Package-List: " does not add empty line
293+
inlineVal := strings.TrimRight(parts[1], " \t")
294+
stanza[lastField] = inlineVal
295+
if inlineVal != "" {
293296
stanza[lastField] += "\n"
294297
}
295298
} else {

deb/format_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,35 @@ func (s *ControlFileSuite) TestReadWriteStanza(c *C) {
128128
c.Assert(strings.HasPrefix(str, "Package: "), Equals, true)
129129
}
130130

131+
// Sources may contain "Package-List: " with a trailing space.
132+
// That trailing space must not be preserved and re-emitted
133+
// as a spurious blank continuation line when the stanza is written back out.
134+
func (s *ControlFileSuite) TestPackageListTrailingSpace(c *C) {
135+
input := "Package-List: \n" +
136+
" bash deb shells required arch=any\n" +
137+
" bash-doc deb doc optional arch=all\n"
138+
139+
r := NewControlFileReader(bytes.NewBufferString(input), false, false)
140+
stanza, err := r.ReadStanza()
141+
c.Assert(err, IsNil)
142+
143+
c.Check(stanza["Package-List"], Equals,
144+
" bash deb shells required arch=any\n"+
145+
" bash-doc deb doc optional arch=all\n")
146+
147+
buf := &bytes.Buffer{}
148+
w := bufio.NewWriter(buf)
149+
err = stanza.Copy().WriteTo(w, true, false, false)
150+
c.Assert(err, IsNil)
151+
c.Assert(w.Flush(), IsNil)
152+
153+
written := buf.String()
154+
c.Assert(strings.Contains(written, "Package-List:\n \n"), Equals, false,
155+
Commentf("spurious blank continuation line found in written output:\n%s", written))
156+
c.Assert(strings.Contains(written, "Package-List:\n bash"), Equals, true,
157+
Commentf("expected Package-List entries not found in written output:\n%s", written))
158+
}
159+
131160
func (s *ControlFileSuite) TestReadWriteInstallerStanza(c *C) {
132161
s.reader = bytes.NewBufferString(installerFile)
133162
r := NewControlFileReader(s.reader, false, true)

0 commit comments

Comments
 (0)