diff --git a/debian/changelog b/debian/changelog index 02925244380220bf81a8f99f96c261e8c25c797c..170a6cadb39b007d6d69adcb340724c2529a9eee 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,24 @@ +python-debian (0.1.18+squeeze1) stable; urgency=low + + * Allow ':' as the first character of a value. This fixes an + implementation error where the paragraph + + Foo: : bar + + would be interpreted as + + {'Foo:': 'bar'} + + by the Python-native parser, while it would be correctly interpreted + as + + {'Foo': ': bar'} + + by both the apt_pkg parser and the Python email library. + (Closes: #597249) + + -- John Wright <jsw@debian.org> Wed, 28 Dec 2011 14:50:57 -0800 + python-debian (0.1.18) unstable; urgency=low * Support installation together with older versions of python-apt. diff --git a/lib/debian/deb822.py b/lib/debian/deb822.py index a0cad6984537bacb2d0ebdf21d399e46d5a41e91..84a4a74471ac0117833ab673f3c2f67cb7f4bbc2 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 891f4cd5fa89a38e47e3995931c92cb76e0ea86a..e29a12d56280667a917503f6103d8e515ee1a68b 100755 --- a/tests/test_deb822.py +++ b/tests/test_deb822.py @@ -726,6 +726,15 @@ Description: python modules to work with Debian-related data formats self.assertEqual(p2['uploaders'], u'Frank Küster <frank@debian.org>') + 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): def test_packages(self):