From ae6cd3bcc76c34b9f449319a7de8859ba4705ca9 Mon Sep 17 00:00:00 2001 From: Daniel Axtens Date: Sat, 8 Jul 2017 00:24:46 +1000 Subject: [PATCH] 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 --- patchwork/parser.py | 2 +- patchwork/tests/mail/0016-no-subject.mbox | 25 +++++++++++++++++++++++ patchwork/tests/test_parser.py | 6 ++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 patchwork/tests/mail/0016-no-subject.mbox 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.""" -- 2.47.3