]> git.ozlabs.org Git - patchwork/commitdiff
[models] Fix exception on mbox view with non-ascii submitter name
authorJeremy Kerr <jk@ozlabs.org>
Thu, 9 Oct 2008 11:50:49 +0000 (22:50 +1100)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 9 Oct 2008 11:50:49 +0000 (22:50 +1100)
We need to unicode the name instead of str-ing it.

Add test.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
apps/patchwork/models.py
apps/patchwork/tests/encodings.py

index 02fb8b4a4e55fc77489145c3280c0b13169abec3..1da1d998bece9d0b2d5046ca0a74666cbaf16318 100644 (file)
@@ -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())
 
index 9dde023eeeb6e1137ea67fb758f8070c9fd9dcfa..397b39ba877887f26eb4d4188deb91e5cf4d2069 100644 (file)
@@ -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()