From 163a579c2fb781423aec455ca6ff3e38a15d39b8 Mon Sep 17 00:00:00 2001 From: Laurent De Marez Date: Mon, 11 Jan 2016 11:05:08 +0100 Subject: [PATCH] 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. --- rest_framework/utils/html.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rest_framework/utils/html.py b/rest_framework/utils/html.py index 3b871027c..121c825c7 100644 --- a/rest_framework/utils/html.py +++ b/rest_framework/utils/html.py @@ -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