From patchwork Wed Feb 7 13:23:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Veronika Kabatova X-Patchwork-Id: 870381 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zc2MH4144z9s71 for ; Thu, 8 Feb 2018 00:32:59 +1100 (AEDT) Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3zc2MH0hQrzF14W for ; Thu, 8 Feb 2018 00:32:59 +1100 (AEDT) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=redhat.com (client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=vkabatov@redhat.com; receiver=) X-Greylist: delayed 516 seconds by postgrey-1.36 at bilbo; Thu, 08 Feb 2018 00:32:50 AEDT Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3zc2M72KHmzF147 for ; Thu, 8 Feb 2018 00:32:50 +1100 (AEDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1FB2A40201A1 for ; Wed, 7 Feb 2018 13:24:11 +0000 (UTC) Received: from vkabatova.usersys.redhat.com (unknown [10.43.17.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93BC0AE7DD; Wed, 7 Feb 2018 13:24:10 +0000 (UTC) From: vkabatov@redhat.com To: patchwork@lists.ozlabs.org Subject: [PATCH v2] Fix CRLF newlines upon submission changes Date: Wed, 7 Feb 2018 14:23:15 +0100 Message-Id: <20180207132315.26050-1-vkabatov@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 07 Feb 2018 13:24:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 07 Feb 2018 13:24:11 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'vkabatov@redhat.com' RCPT:'' X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" From: Veronika Kabatova 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 Reviewed-by: Stephen Finucane --- Changes since v1: add comment to explain reasoning in code --- patchwork/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) 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