[python-debian/master] Allow ':' as the first character of a value
John Wright
jsw at debian.org
Sun Jul 3 09:36:39 UTC 2011
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 | 3 +++
lib/debian/deb822.py | 8 +++++---
tests/test_deb822.py | 9 +++++++++
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index dcb0873..3fcedff 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -3,6 +3,9 @@ python-debian (0.1.21) UNRELEASED; urgency=low
[ Tshepang Lekhonkhobe ]
* test_changelog.py: Close open files. (Closes: #625672)
+ [ John Wright ]
+ * Allow ':' as the first character of a value. (Closes: #597249)
+
-- John Wright <jsw at debian.org> Sat, 02 Jul 2011 23:20:27 -0700
python-debian (0.1.20) unstable; urgency=low
diff --git a/lib/debian/deb822.py b/lib/debian/deb822.py
index a0cad69..84a4a74 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 891f4cd..e29a12d 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 at 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):
--
1.7.2.5
More information about the pkg-python-debian-commits
mailing list