Skip to content

Commit 431ec34

Browse files
committed
Source files: fix empty line in Package-List
1 parent 619088d commit 431ec34

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

deb/format.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,14 @@ 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: " (trailing space, as used by Debian) is
293+
// treated identically to "Package-List:" (no inline content).
294+
// Without this, the trailing space is stored and later
295+
// re-emitted as a spurious blank continuation line.
296+
inlineVal := strings.TrimRight(parts[1], " \t")
297+
stanza[lastField] = inlineVal
298+
if inlineVal != "" {
293299
stanza[lastField] += "\n"
294300
}
295301
} else {

deb/format_test.go

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

131+
// TestPackageListTrailingSpace is a regression test for
132+
// https://github.com/aptly-dev/aptly/issues/1538.
133+
// Upstream Debian Sources files write "Package-List: " with a trailing space
134+
// on the header line. That trailing space must not be preserved and re-emitted
135+
// as a spurious blank continuation line when the stanza is written back out.
136+
func (s *ControlFileSuite) TestPackageListTrailingSpace(c *C) {
137+
// Input mirrors the format used by real Debian Sources files:
138+
// the "Package-List:" header carries a trailing space, not bare colon.
139+
input := "Package-List: \n" +
140+
" bash deb shells required arch=any\n" +
141+
" bash-doc deb doc optional arch=all\n"
142+
143+
r := NewControlFileReader(bytes.NewBufferString(input), false, false)
144+
stanza, err := r.ReadStanza()
145+
c.Assert(err, IsNil)
146+
147+
// The stored value must equal what a bare "Package-List:\n" header gives:
148+
// no leading whitespace / blank line, just the continuation lines.
149+
c.Check(stanza["Package-List"], Equals,
150+
" bash deb shells required arch=any\n"+
151+
" bash-doc deb doc optional arch=all\n")
152+
153+
// Round-trip: written output must not contain a spurious blank line.
154+
buf := &bytes.Buffer{}
155+
w := bufio.NewWriter(buf)
156+
err = stanza.Copy().WriteTo(w, true, false, false)
157+
c.Assert(err, IsNil)
158+
c.Assert(w.Flush(), IsNil)
159+
160+
written := buf.String()
161+
c.Assert(strings.Contains(written, "Package-List:\n \n"), Equals, false,
162+
Commentf("spurious blank continuation line found in written output:\n%s", written))
163+
c.Assert(strings.Contains(written, "Package-List:\n bash"), Equals, true,
164+
Commentf("expected Package-List entries not found in written output:\n%s", written))
165+
}
166+
131167
func (s *ControlFileSuite) TestReadWriteInstallerStanza(c *C) {
132168
s.reader = bytes.NewBufferString(installerFile)
133169
r := NewControlFileReader(s.reader, false, true)

0 commit comments

Comments
 (0)