From b2f9c74ed1cd246022ab52d239eeb33f950dcc70 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Thu, 17 Oct 2013 18:07:47 +0200 Subject: [1.6.x] Fixed #21282 -- Made HttpResponse.serialize_headers accept latin-1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks Raphaël Barrois for the report and the initial patch and Aymeric Augustin for the review. Backport of a14f087233 from master. --- tests/httpwrappers/tests.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/httpwrappers/tests.py b/tests/httpwrappers/tests.py index 7eb11b1dc7..ed32ea0478 100644 --- a/tests/httpwrappers/tests.py +++ b/tests/httpwrappers/tests.py @@ -254,6 +254,7 @@ class HttpResponseTests(unittest.TestCase): r['key'] = 'test'.encode('ascii') self.assertEqual(r['key'], str('test')) self.assertIsInstance(r['key'], str) + self.assertIn(b'test', r.serialize_headers()) # Latin-1 unicode or bytes values are also converted to native strings. r['key'] = 'café' @@ -262,11 +263,13 @@ class HttpResponseTests(unittest.TestCase): r['key'] = 'café'.encode('latin-1') self.assertEqual(r['key'], smart_str('café', 'latin-1')) self.assertIsInstance(r['key'], str) + self.assertIn('café'.encode('latin-1'), r.serialize_headers()) # Other unicode values are MIME-encoded (there's no way to pass them as bytes). r['key'] = '†' self.assertEqual(r['key'], str('=?utf-8?b?4oCg?=')) self.assertIsInstance(r['key'], str) + self.assertIn(b'=?utf-8?b?4oCg?=', r.serialize_headers()) # The response also converts unicode or bytes keys to strings, but requires # them to contain ASCII -- cgit v1.3