]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
Fix CRLF newlines upon submission changes
authorVeronika Kabatova <vkabatov@redhat.com>
Wed, 7 Feb 2018 13:23:15 +0000 (14:23 +0100)
committerStephen Finucane <stephen@that.guru>
Fri, 9 Feb 2018 10:28:01 +0000 (10:28 +0000)
After changing submission via admin interface, CRLF newlines are
suddenly present in the body. Replace them back to '\n'.

The issue was found after modifying submission via admin interface
using Python 2 and downloading the respective mbox file (git choked on
downloaded patch because of malformed line endings). Python 3's mail
module uses '\n' internally so the problem doesn't manifest there, but
the content received by Django/JS is still saved in the database with
CRLF line endings which shouldn't be there.

Signed-off-by: Veronika Kabatova <vkabatov@redhat.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
patchwork/models.py

index 3bf7c72dbe08841d209678ff2d954c7bb2bf5179..a8bb015ba2420362a1ddf6454b7ff2f1c402949d 100644 (file)
@@ -328,6 +328,14 @@ class EmailMixin(models.Model):
         return ''.join([match.group(0) + '\n' for match in
                         self.response_re.finditer(self.content)])
 
+    def save(self, *args, **kwargs):
+        # Modifying a submission via admin interface changes '\n' newlines in
+        # message content to '\r\n'. We need to fix them to avoid problems,
+        # especially as git complains about malformed patches when PW runs
+        # on PY2
+        self.content = self.content.replace('\r\n', '\n')
+        super(EmailMixin, self).save(*args, **kwargs)
+
     class Meta:
         abstract = True