diff mbox series

[v2] Fix CRLF newlines upon submission changes

Message ID 20180207132315.26050-1-vkabatov@redhat.com
State Accepted
Headers show
Series [v2] Fix CRLF newlines upon submission changes | expand

Checks

Context Check Description
dja/snowpatch-snowpatch_job_snowpatch-patchwork success Test snowpatch/job/snowpatch-patchwork on branch master
dja/snowpatch-0_1_0 success master/apply_patch Successfully applied

Commit Message

Veronika Kabatova Feb. 7, 2018, 1:23 p.m. UTC
From: Veronika Kabatova <vkabatov@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@redhat.com>
---
Changes since v1: add comment to explain reasoning in code
---
 patchwork/models.py | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Stephen Finucane Feb. 9, 2018, 10:27 a.m. UTC | #1
On Wed, 2018-02-07 at 14:23 +0100, vkabatov@redhat.com wrote:
> From: Veronika Kabatova <vkabatov@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@redhat.com>

Looks a-ok to me. Thanks!

Reviewed-by: Stephen Finucane <stephen@that.guru>

...and applied.
diff mbox series

Patch

diff --git a/patchwork/models.py b/patchwork/models.py
index 3bf7c72..a8bb015 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -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