[Pkg-python-debian-commits] r83 trunk: * debian_bundle/deb822.py, debian_bundle/test_deb822.py

jsw at debian.org jsw at debian.org
Wed Sep 12 00:16:40 UTC 2007


------------------------------------------------------------
revno: 83
committer: jsw at debian.org
branch nick: trunk
timestamp: Tue 2007-09-11 18:16:40 -0600
message:
  * debian_bundle/deb822.py, debian_bundle/test_deb822.py
    - Bug fix: Allow fields with blank (empty string) values.  Previously,
      these were parsed fine, but if you tried to dump the resulting Deb822
      object, you'd get an IndexError (because of how we handled fields whose
      values start with newlines).  Added a test case.
modified:
  debian/changelog
  debian_bundle/deb822.py
  debian_bundle/test_deb822.py
-------------- next part --------------
=== modified file 'debian/changelog'
--- a/debian/changelog	2007-09-08 08:20:58 +0000
+++ b/debian/changelog	2007-09-12 00:16:40 +0000
@@ -1,8 +1,13 @@
 python-debian (0.1.7) UNRELEASED; urgency=low
 
-  * NOT YET RELEASED
+  [ John Wright ]
+  * debian_bundle/deb822.py, debian_bundle/test_deb822.py
+    - Bug fix: Allow fields with blank (empty string) values.  Previously,
+      these were parsed fine, but if you tried to dump the resulting Deb822
+      object, you'd get an IndexError (because of how we handled fields whose
+      values start with newlines).  Added a test case.
 
- -- Stefano Zacchiroli <zack at debian.org>  Sat, 08 Sep 2007 10:20:37 +0200
+ -- John Wright <jsw at debian.org>  Tue, 11 Sep 2007 18:09:21 -0600
 
 python-debian (0.1.6) unstable; urgency=low
 

=== modified file 'debian_bundle/deb822.py'
--- a/debian_bundle/deb822.py	2007-07-26 17:59:33 +0000
+++ b/debian_bundle/deb822.py	2007-09-12 00:16:40 +0000
@@ -265,9 +265,9 @@
         else:
             return_string = False
         for key, value in self.iteritems():
-            if value[0] == '\n':
+            if not value or value[0] == '\n':
                 # Avoid trailing whitespace after "Field:" if it's on its own
-                # line
+                # line or the value is empty
                 fd.write('%s:%s\n' % (key, value))
             else:
                 fd.write('%s: %s\n' % (key, value))

=== modified file 'debian_bundle/test_deb822.py'
--- a/debian_bundle/test_deb822.py	2007-07-20 22:29:35 +0000
+++ b/debian_bundle/test_deb822.py	2007-09-12 00:16:40 +0000
@@ -412,7 +412,24 @@
                              "Multiline fields that do not start with newline "
                              "should have a space between the colon and the "
                              "beginning of the value")
-        
+
+    def test_blank_value(self):
+        """Fields with blank values are parsable--so they should be dumpable"""
+
+        d = deb822.Deb822()
+        d['Foo'] = 'bar'
+        d['Baz'] = ''
+        d['Another-Key'] = 'another value'
+        
+        # Previous versions would raise an exception here -- this makes the
+        # test fail and gives useful information, so I won't try to wrap around
+        # it.
+        dumped = d.dump()
+        
+        # May as well make sure the resulting string is what we want
+        expected = "Foo: bar\nBaz:\nAnother-Key: another value\n"
+        self.assertEqual(dumped, expected)
+
 
 if __name__ == '__main__':
     unittest.main()



More information about the pkg-python-debian-commits mailing list