[1.6.x] Fixed #20961 -- Fixed HttpResponse default empty content

Thanks epandurski at gmail.com for the report.
Backport of f4e980456 from master.
This commit is contained in:
Claude Paroz 2013-08-24 18:08:05 +02:00
parent 2a166623a6
commit 2c08d474a8
2 changed files with 8 additions and 1 deletions

View File

@ -323,7 +323,7 @@ class HttpResponse(HttpResponseBase):
streaming = False
def __init__(self, content='', *args, **kwargs):
def __init__(self, content=b'', *args, **kwargs):
super(HttpResponse, self).__init__(*args, **kwargs)
# Content is a bytestring. See the `content` property methods.
self.content = content

View File

@ -398,6 +398,13 @@ class HttpResponseTests(unittest.TestCase):
self.assertEqual(r.tell(), 6)
self.assertEqual(r.content, b'abcdef')
# with Content-Encoding header
r = HttpResponse()
r['Content-Encoding'] = 'winning'
r.write(b'abc')
r.write(b'def')
self.assertEqual(r.content, b'abcdef')
def test_unsafe_redirect(self):
bad_urls = [
'data:text/html,<script>window.alert("xss")</script>',