Loading django/http/response.py +2 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ from __future__ import unicode_literals import datetime import time import sys from email.header import Header try: from urllib.parse import urlparse Loading Loading @@ -160,7 +161,7 @@ class HttpResponseBase(six.Iterator): except UnicodeError as e: if mime_encode: # Wrapping in str() is a workaround for #12422 under Python 2. value = str(Header(value, 'utf-8').encode()) value = str(Header(value, 'utf-8', maxlinelen=sys.maxsize).encode()) else: e.reason += ', HTTP response headers must be in %s format' % charset raise Loading tests/httpwrappers/tests.py +7 −0 Original line number Diff line number Diff line Loading @@ -290,6 +290,13 @@ class HttpResponseTests(unittest.TestCase): self.assertRaises(UnicodeError, r.__setitem__, 'føø', 'bar') self.assertRaises(UnicodeError, r.__setitem__, 'føø'.encode('utf-8'), 'bar') def test_long_line(self): # Bug #20889: long lines trigger newlines to be added to headers # (which is not allowed due to bug #10188) h = HttpResponse() f = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz a\xcc\x88'.encode('latin-1') f = f.decode('utf-8') h['Content-Disposition'] = u'attachment; filename="%s"' % f def test_newlines_in_headers(self): # Bug #10188: Do not allow newlines in headers (CR or LF) Loading Loading
django/http/response.py +2 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ from __future__ import unicode_literals import datetime import time import sys from email.header import Header try: from urllib.parse import urlparse Loading Loading @@ -160,7 +161,7 @@ class HttpResponseBase(six.Iterator): except UnicodeError as e: if mime_encode: # Wrapping in str() is a workaround for #12422 under Python 2. value = str(Header(value, 'utf-8').encode()) value = str(Header(value, 'utf-8', maxlinelen=sys.maxsize).encode()) else: e.reason += ', HTTP response headers must be in %s format' % charset raise Loading
tests/httpwrappers/tests.py +7 −0 Original line number Diff line number Diff line Loading @@ -290,6 +290,13 @@ class HttpResponseTests(unittest.TestCase): self.assertRaises(UnicodeError, r.__setitem__, 'føø', 'bar') self.assertRaises(UnicodeError, r.__setitem__, 'føø'.encode('utf-8'), 'bar') def test_long_line(self): # Bug #20889: long lines trigger newlines to be added to headers # (which is not allowed due to bug #10188) h = HttpResponse() f = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz a\xcc\x88'.encode('latin-1') f = f.decode('utf-8') h['Content-Disposition'] = u'attachment; filename="%s"' % f def test_newlines_in_headers(self): # Bug #10188: Do not allow newlines in headers (CR or LF) Loading