From 3b5a7ddbe6f230bcb659104765a2da0837a3f283 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Sun, 12 Nov 2017 18:38:41 +0100 Subject: changelog: handle comma in maintainers name Thanks: Andreas Beckmann for the proposed fix Closes: #737623 --- gbp/deb/changelog.py | 21 +++++++++++++++++++-- tests/30_test_deb_changelog.py | 26 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 tests/30_test_deb_changelog.py diff --git a/gbp/deb/changelog.py b/gbp/deb/changelog.py index bcda3f4c..1d499821 100644 --- a/gbp/deb/changelog.py +++ b/gbp/deb/changelog.py @@ -190,14 +190,15 @@ class ChangeLog(object): """ The author of the last modification """ - return email.utils.parseaddr(self._cp['Maintainer'])[0] + + return self._parse_maint(self._cp['Maintainer'])[0] @property def email(self): """ The author's email """ - return email.utils.parseaddr(self._cp['Maintainer'])[1] + return self._parse_maint(self._cp['Maintainer'])[1] @property def date(self): @@ -326,3 +327,19 @@ class ChangeLog(object): def get_changes(self, since='0~'): return self._run_parsechangelog(['-v%s' % since, '-SChanges']) + + @staticmethod + def _parse_maint(maintainer): + """ + Parse maintainer + + Mostly rfc822 but we allow for commas + """ + def _quote(u): + return u.replace(',', '##comma##') + + def _unquote(q): + return q.replace('##comma##', ',') + + name, mail = email.utils.parseaddr(_quote(maintainer or '')) + return (_unquote(name), _unquote(mail)) diff --git a/tests/30_test_deb_changelog.py b/tests/30_test_deb_changelog.py new file mode 100644 index 00000000..8587a675 --- /dev/null +++ b/tests/30_test_deb_changelog.py @@ -0,0 +1,26 @@ +# vim: set fileencoding=utf-8 : + +""" +Test L{gbp.deb.changelog.Changelog} + +Test things here that don't fit nicely into the doctests that +also make up the API documentation. +""" + +import unittest + +from gbp.deb.changelog import ChangeLog + + +class TestQuoting(unittest.TestCase): + def test_comma(self): + """Test we properly parse maitainers with comma #737623""" + changes = """git-buildpackage (0.9.2) unstable; urgency=low + + * List of changes + + -- Guido Günther, aftercomma Sun, 12 Nov 2017 19:00:00 +0200 +""" + cl = ChangeLog(changes) + self.assertEquals(cl.author, 'Guido Günther, aftercomma') + self.assertEquals(cl.email, 'agx@sigxcpu.org') -- cgit v1.2.3