Skip to content

Commit

Permalink
Merge pull request #1743 from hubo1016/2.0
Browse files Browse the repository at this point in the history
Fix crash on multipart/form-data post
  • Loading branch information
fafhrd91 authored Mar 24, 2017
2 parents 20ef6f5 + 932b231 commit a666d7f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Georges Dubus
Greg Holt
Gregory Haynes
Günther Jena
Hu Bo
Hugo Herter
Igor Pavlov
Ingmar Steen
Expand Down
3 changes: 2 additions & 1 deletion aiohttp/web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ def post(self):
out.add(field.name, ff)
else:
value = yield from field.read(decode=True)
if content_type.startswith('text/'):
if content_type is None or \
content_type.startswith('text/'):
charset = field.get_charset(default='utf-8')
value = value.decode(charset)
out.add(field.name, value)
Expand Down
22 changes: 22 additions & 0 deletions tests/test_web_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,28 @@ def test_make_too_big_request_adjust_limit(loop):
assert len(txt) == 1024**2 + 1


@asyncio.coroutine
def test_multipart_formdata(loop):
payload = StreamReader(loop=loop)
payload.feed_data(b"""-----------------------------326931944431359\r
Content-Disposition: form-data; name="a"\r
\r
b\r
-----------------------------326931944431359\r
Content-Disposition: form-data; name="c"\r
\r
d\r
-----------------------------326931944431359--\r\n""")
content_type = "multipart/form-data; boundary="\
"---------------------------326931944431359"
payload.feed_eof()
req = make_mocked_request('POST', '/',
headers={'CONTENT-TYPE': content_type},
payload=payload)
result = yield from req.post()
assert dict(result) == {'a': 'b', 'c': 'd'}


@asyncio.coroutine
def test_make_too_big_request_limit_None(loop):
payload = StreamReader(loop=loop)
Expand Down

0 comments on commit a666d7f

Please sign in to comment.