From: Stephen Finucane Date: Tue, 24 Jan 2023 23:31:22 +0000 (+0000) Subject: Correctly append tags on patches without commit details X-Git-Tag: v3.1.2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f23e7fe72ba5b7625fa0155266b4372419f385a8;p=thirdparty%2Fpatchwork.git Correctly append tags on patches without commit details 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 Closes: #516 Cc: siddhesh@gotplt.org (cherry picked from commit 05da32fef9140412bf0e822ce7f9706cb8aa7b5b) --- diff --git a/patchwork/tests/views/test_utils.py b/patchwork/tests/views/test_utils.py index e10c3bde..6df42249 100644 --- a/patchwork/tests/views/test_utils.py +++ b/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 a/patchwork/views/utils.py b/patchwork/views/utils.py index 1f7ee0da..91b2ef1b 100644 --- a/patchwork/views/utils.py +++ b/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