Bug#597249: [PATCH] Allow ':' as the first character of a value

John Wright jsw at debian.org
Sat Sep 18 08:17:13 UTC 2010


The regular expression that matched keys was too loose, so things like

  Foo: : bar

would get parsed as

  {'Foo:': 'bar'}

instead of the correct value (which is also returned by both apt_pkg and
the email package),

  {'Foo': ': bar'}

Closes: #597249
---
 debian/changelog     |    1 +
 lib/debian/deb822.py |    8 +++++---
 tests/test_deb822.py |    8 ++++++++
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 492b5df..4010029 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,6 +1,7 @@
 python-debian (0.1.19) UNRELEASED; urgency=low
 
   * Avoid dumping unparseable data. (Closes: #597120)
+  * Allow ':' as the first character of a value. (Closes: #597249)
 
  -- John Wright <jsw at debian.org>  Sat, 18 Sep 2010 00:47:04 -0600
 
diff --git a/lib/debian/deb822.py b/lib/debian/deb822.py
index fc87124..47c921d 100644
--- a/lib/debian/deb822.py
+++ b/lib/debian/deb822.py
@@ -317,9 +317,11 @@ class Deb822(Deb822Dict):
     ###
 
     def _internal_parser(self, sequence, fields=None):
-        single = re.compile("^(?P<key>\S+)\s*:\s*(?P<data>\S.*?)\s*$")
-        multi = re.compile("^(?P<key>\S+)\s*:\s*$")
-        multidata = re.compile("^\s(?P<data>.+?)\s*$")
+        # The key is non-whitespace, non-colon characters before any colon.
+        key_part = r"^(?P<key>[^: \t\n\r\f\v]+)\s*:\s*"
+        single = re.compile(key_part + r"(?P<data>\S.*?)\s*$")
+        multi = re.compile(key_part + r"$")
+        multidata = re.compile(r"^\s(?P<data>.+?)\s*$")
 
         wanted_field = lambda f: fields is None or f in fields
 
diff --git a/tests/test_deb822.py b/tests/test_deb822.py
index 64fd77a..b03b13f 100755
--- a/tests/test_deb822.py
+++ b/tests/test_deb822.py
@@ -753,6 +753,14 @@ Description: python modules to work with Debian-related data formats
         d['Files'] = [{'md5sum': 'deadbeef', 'size': '9605', 'name': 'bad\n'}]
         self.assertRaises(ValueError, d.get_as_string, 'files')
 
+    def test_bug597249_colon_as_first_value_character(self):
+        """Colon should be allowed as the first value character. See #597249.
+        """
+
+        data = 'Foo: : bar'
+        parsed = {'Foo': ': bar'}
+        self.assertWellParsed(deb822.Deb822(data), parsed)
+
 
 class TestPkgRelations(unittest.TestCase):
 
-- 
1.7.1






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