From: Daniel Axtens Date: Fri, 7 Jul 2017 14:24:46 +0000 (+1000) Subject: parser: fix parsing of messages with empty subjects X-Git-Tag: v2.0.0~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ae6cd3bcc76c34b9f449319a7de8859ba4705ca9;p=thirdparty%2Fpatchwork.git parser: fix parsing of messages with empty subjects The fuzz fixups made the test too strict ("if not subject" rather than "if subject is None") in an attempt to catch broken subject headers. This broke parsing of messages with an empty subject. Fix it and add a test. Signed-off-by: Daniel Axtens Reviewed-by: Stephen Finucane --- diff --git a/patchwork/parser.py b/patchwork/parser.py index eab0a7d3..1568bc44 100644 --- a/patchwork/parser.py +++ b/patchwork/parser.py @@ -617,7 +617,7 @@ def clean_subject(subject, drop_prefixes=None): prefix_re = re.compile(r'^\[([^\]]*)\]\s*(.*)$') subject = clean_header(subject) - if not subject: + if subject is None: raise ValueError("Invalid 'Subject' header") if drop_prefixes is None: diff --git a/patchwork/tests/mail/0016-no-subject.mbox b/patchwork/tests/mail/0016-no-subject.mbox new file mode 100644 index 00000000..6c4d7c90 --- /dev/null +++ b/patchwork/tests/mail/0016-no-subject.mbox @@ -0,0 +1,25 @@ +From: "Yann E. MORIN" +Subject: +Date: Tue, 8 Oct 2013 22:09:47 +0000 +Message-ID: + +Rename patches to follow standard naming scheme. + +Signed-off-by: "Yann E. MORIN" +--- + ...d-pkgconfig-files.patch => rpi-userland-000-add-pkgconfig-files.patch} | 0 + ...erland-001-makefiles-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch} | 0 + 2 files changed, 0 insertions(+), 0 deletions(-) + rename package/rpi-userland/{rpi-userland-add-pkgconfig-files.patch => rpi-userland-000-add-pkgconfig-files.patch} (100%) + rename package/rpi-userland/{rpi-userland-makefiles-0001-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch => rpi-userland-001-makefiles-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch} (100%) + +diff --git a/package/rpi-userland/rpi-userland-add-pkgconfig-files.patch b/package/rpi-userland/rpi-userland-000-add-pkgconfig-files.patch +similarity index 100% +rename from package/rpi-userland/rpi-userland-add-pkgconfig-files.patch +rename to package/rpi-userland/rpi-userland-000-add-pkgconfig-files.patch +diff --git a/package/rpi-userland/rpi-userland-makefiles-0001-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch b/package/rpi-userland/rpi-userland-001-makefiles-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch +similarity index 100% +rename from package/rpi-userland/rpi-userland-makefiles-0001-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch +rename to package/rpi-userland/rpi-userland-001-makefiles-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch +-- +1.8.1.2 diff --git a/patchwork/tests/test_parser.py b/patchwork/tests/test_parser.py index 34c15844..52de351e 100644 --- a/patchwork/tests/test_parser.py +++ b/patchwork/tests/test_parser.py @@ -609,6 +609,12 @@ class PatchParseTest(PatchTest): # Confirm we got both markers self.assertEqual(2, diff.count('\ No newline at end of file')) + def test_no_subject(self): + """Validate parsing a mail with no subject.""" + diff, message = self._find_content('0016-no-subject.mbox') + self.assertTrue(diff is not None) + self.assertTrue(message is not None) + class EncodingParseTest(TestCase): """Test parsing of patches with different encoding issues."""