From: Jeremy Kerr Date: Thu, 9 Oct 2008 11:50:49 +0000 (+1100) Subject: [models] Fix exception on mbox view with non-ascii submitter name X-Git-Url: http://git.ozlabs.org/?p=patchwork;a=commitdiff_plain;h=94ae2713d4aca80b7dc1168a60f98bbe38d86e12 [models] Fix exception on mbox view with non-ascii submitter name We need to unicode the name instead of str-ing it. Add test. Signed-off-by: Jeremy Kerr --- diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py index 02fb8b4..1da1d99 100644 --- a/apps/patchwork/models.py +++ b/apps/patchwork/models.py @@ -252,7 +252,7 @@ class Patch(models.Model): mail['Subject'] = self.name mail['Date'] = email.utils.formatdate( time.mktime(self.date.utctimetuple())) - mail['From'] = str(self.submitter) + mail['From'] = unicode(self.submitter) mail['X-Patchwork-Id'] = str(self.id) mail.set_unixfrom('From patchwork ' + self.date.ctime()) diff --git a/apps/patchwork/tests/encodings.py b/apps/patchwork/tests/encodings.py index 9dde023..397b39b 100644 --- a/apps/patchwork/tests/encodings.py +++ b/apps/patchwork/tests/encodings.py @@ -20,7 +20,7 @@ import unittest import os import time -from patchwork.models import Patch +from patchwork.models import Patch, Person from patchwork.tests.utils import defaults, read_patch from django.test import TestCase from django.test.client import Client @@ -62,3 +62,26 @@ class UTF8PatchViewTest(TestCase): defaults.patch_author_person.delete() defaults.project.delete() +class UTF8HeaderPatchViewTest(UTF8PatchViewTest): + patch_filename = '0002-utf-8.patch' + patch_encoding = 'utf-8' + patch_author_name = u'P\xe4tch Author' + + def setUp(self): + defaults.project.save() + self.patch_author = Person(name = self.patch_author_name, + email = defaults.patch_author_person.email) + self.patch_author.save() + self.patch_content = read_patch(self.patch_filename, + encoding = self.patch_encoding) + self.patch = Patch(project = defaults.project, + msgid = 'x', name = defaults.patch_name, + submitter = self.patch_author, + content = self.patch_content) + self.patch.save() + self.client = Client() + + def tearDown(self): + self.patch.delete() + self.patch_author.delete() + defaults.project.delete()