mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-08 06:14:47 +03:00
Fix multiple value bug in html.parse_html_dict()
It is possible that a key in a MultiValueDict has multiple values, lists are represented this way. When accessing a key in a MultiValueDict it only returns the last element of that key. This becomes a problem when parsing an html dict with a list inside of it. To fix this problem we have to get and set the value using .getlist() and .setlist(). This commit solves a bug that caused a list in a nested serializer to not being properly parsed if it was sent as multipart formated data.
This commit is contained in:
parent
877ed6edc2
commit
163a579c2f
|
@ -80,10 +80,12 @@ def parse_html_dict(dictionary, prefix=''):
|
|||
"""
|
||||
ret = MultiValueDict()
|
||||
regex = re.compile(r'^%s\.(.+)$' % re.escape(prefix))
|
||||
for field, value in dictionary.items():
|
||||
for field in dictionary:
|
||||
match = regex.match(field)
|
||||
if not match:
|
||||
continue
|
||||
key = match.groups()[0]
|
||||
ret[key] = value
|
||||
value = dictionary.getlist(field)
|
||||
ret.setlist(key, value)
|
||||
|
||||
return ret
|
||||
|
|
Loading…
Reference in New Issue
Block a user