Skip to content

Commit 07c7ba3

Browse files
committed
Fix a bug: now web.Request.POST() processes duplicate field names
1 parent ab2807f commit 07c7ba3

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

aiohttp/web.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def POST(self):
358358
value = supported_tranfer_encoding[
359359
transfer_encoding](value)
360360
out.add(field.name, value)
361-
self._post = MultiDict(out)
361+
self._post = MultiDict(out.items(getall=True))
362362
return self._post
363363

364364
# @asyncio.coroutine

tests/test_web_functional.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import unittest
66
import tempfile
77
from aiohttp import web, request, FormData
8+
from aiohttp.multidict import MultiDict
89

910

1011
class TestWebFunctional(unittest.TestCase):
@@ -267,3 +268,24 @@ def go(tmpdirname, filename):
267268
fp.flush()
268269
fp.seek(0)
269270
self.loop.run_until_complete(go(tmpdirname, filename))
271+
272+
def test_post_form_with_duplicate_keys(self):
273+
274+
@asyncio.coroutine
275+
def handler(request):
276+
data = yield from request.POST()
277+
lst = list(sorted(data.items(getall=True)))
278+
self.assertEqual([('a', '1'), ('a', '2')], lst)
279+
return web.Response(request, b'OK')
280+
281+
@asyncio.coroutine
282+
def go():
283+
_, _, url = yield from self.create_server('POST', '/', handler)
284+
resp = yield from request('POST', url,
285+
data=MultiDict([('a', 1), ('a', 2)]),
286+
loop=self.loop)
287+
self.assertEqual(200, resp.status)
288+
txt = yield from resp.text()
289+
self.assertEqual('OK', txt)
290+
291+
self.loop.run_until_complete(go())

0 commit comments

Comments
 (0)