@@ -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+
131167func (s * ControlFileSuite ) TestReadWriteInstallerStanza (c * C ) {
132168 s .reader = bytes .NewBufferString (installerFile )
133169 r := NewControlFileReader (s .reader , false , true )
0 commit comments