[PATCH] Fix CRLF newlines upon submission changes

vkabatov at redhat.com vkabatov at redhat.com
Tue Feb 6 23:27:09 AEDT 2018

From: Veronika Kabatova <vkabatov at redhat.com>

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 at redhat.com>
 patchwork/models.py | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/patchwork/models.py b/patchwork/models.py
index 3bf7c72..411af63 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -328,6 +328,10 @@ class EmailMixin(models.Model):
         return ''.join([match.group(0) + '\n' for match in
+    def save(self, *args, **kwargs):
+        self.content = self.content.replace('\r\n', '\n')
+        super(EmailMixin, self).save(*args, **kwargs)
     class Meta:
         abstract = True

More information about the Patchwork mailing list