]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
Correctly append tags on patches without commit details
authorStephen Finucane <stephen@that.guru>
Tue, 24 Jan 2023 23:31:22 +0000 (23:31 +0000)
committerStephen Finucane <stephen@that.guru>
Wed, 25 Jan 2023 18:11:26 +0000 (18:11 +0000)
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
(cherry picked from commit 05da32fef9140412bf0e822ce7f9706cb8aa7b5b)

patchwork/tests/views/test_utils.py
patchwork/views/utils.py

index e10c3bdef3c06e5882266c13a024066e2cb6c2f9..6df4224954af4783cfa11fcca7234bb68d3c18fe 100644 (file)
@@ -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)
index 1f7ee0da89c502d199e25e27e457641e59f228cc..91b2ef1b7189645dfef659582e56a886429c586b 100644 (file)
@@ -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