diff mbox series

Correctly append tags on patches without commit details

Message ID 20230124235756.146520-1-stephen@that.guru
State New
Headers show
Series Correctly append tags on patches without commit details | expand

Commit Message

Stephen Finucane Jan. 24, 2023, 11:57 p.m. UTC
Only a commit summary (a.k.a. patch subject) is necessary in Git: we
don't need details. The regex we were using to search for postscripts
however assumed that there would be _something_ before the postscript,
resulting in a newline. This wasn't the case. Correct this assumption by
instead using 're.MULTILINE' and matching on '^' and '$' for newlines
instead of '\n'.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Closes: #516
Cc: siddhesh@gotplt.org
---
 patchwork/tests/views/test_utils.py | 23 +++++++++++++++++++++++
 patchwork/views/utils.py            |  4 ++--
 2 files changed, 25 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git patchwork/tests/views/test_utils.py patchwork/tests/views/test_utils.py
index 6b980f9d..8b795815 100644
--- patchwork/tests/views/test_utils.py
+++ patchwork/tests/views/test_utils.py
@@ -66,6 +66,29 @@  class MboxPatchResponseTest(TestCase):
         mbox = utils.patch_to_mbox(self.patch)
         self.assertIn('Acked-by: 1\nAcked-by: 2\n', mbox)
 
+    def test_bug_516(self):
+        """Test that tags are appended if a patch description is unset."""
+        patch = create_patch(
+            content=(
+                '---\n'
+                ' manual/string.texi | 2 +-\n'
+                ' 1 file changed, 1 insertion(+), 1 deletion(-)'
+            ),
+        )
+        create_patch_comment(patch=patch, content='Acked-by: 2\n')
+
+        mbox = utils.patch_to_mbox(patch)
+        # the epilog comes after the tags
+        self.assertIn(
+            (
+                'Acked-by: 2\n'
+                '---\n'
+                ' manual/string.texi | 2 +-\n'
+                ' 1 file changed, 1 insertion(+), 1 deletion(-)\n'
+            ),
+            mbox,
+        )
+
     def _test_header_passthrough(self, header):
         patch = create_patch(headers=header + '\n')
         mbox = utils.patch_to_mbox(patch)
diff --git patchwork/views/utils.py patchwork/views/utils.py
index 1f7ee0da..91b2ef1b 100644
--- patchwork/views/utils.py
+++ patchwork/views/utils.py
@@ -48,7 +48,7 @@  def _submission_to_mbox(submission):
     """
     is_patch = isinstance(submission, Patch)
 
-    postscript_re = re.compile('\n-{2,3} ?\n')
+    postscript_re = re.compile('^-{2,3} ?$', re.MULTILINE)
     body = ''
 
     if submission.content:
@@ -71,7 +71,7 @@  def _submission_to_mbox(submission):
             body += comment.patch_responses
 
     if postscript:
-        body += '---\n' + postscript + '\n'
+        body += '---' + postscript + '\n'
 
     if is_patch and submission.diff:
         body += '\n' + submission.diff