Skip to content

parse_html_list works incorrect #7186

@makegodhere

Description

@makegodhere

In function

def parse_html_list(dictionary, prefix='', default=None):

We have:

ret = {}
regex = re.compile(r'^%s\[([0-9]+)\](.*)$' % re.escape(prefix))
for field, value in dictionary.items():
    match = regex.match(field)
    if not match:
        continue
    index, key = match.groups()
    index = int(index)
    if not key:
        ret[index] = value
    elif isinstance(ret.get(index), dict):
        ret[index][key] = value
    else:
        ret[index] = MultiValueDict({key: [value]})

# return the items of the ``ret`` dict, sorted by key, or ``default`` if the dict is empty
return [ret[item] for item in sorted(ret)] if ret else default

But if we send form-data request like this (list of objects for expamle):

firstName:[{"language": 1, "text": "Test"}, {"language": 2, "text": "Test2"}]

Function parse_html_list will work incorrect.
We need in this function something like this:

ret = []
for field, value in dictionary.items():
    if field == prefix:
        try:
            ret = json.loads(value)
            break
        except:
            continue
# return the items of the ``ret`` dict, sorted by key, or ``default`` if the dict is empty
return ret if ret else default

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions