Skip to content

Make SimpleDataBinder handle multiple indexers #15064

@Kernvirus

Description

@Kernvirus

Feature description

Hello,

SimpleDataBinder uses this regex to parse the indexer and it's value from a value it wants to map:
static final INDEXED_PROPERTY_REGEX = /(.*)\[\s*([^\s]*)\s*\]\s*$/

But this regex will always choose the last indexer when there are multiple present. Example:
propName = 'columns[0]['data']'
will be matched as

indexedPropertyName = 'columns[0]'
index = 'data'

I'd argue that this is wrong. A groovy property is not allowed to be named columns[0] anyways (right?) so matching that makes no sense. It should instead consider the first indexer as the indexer that matters. It should be:

indexedPropertyName = 'columns'
index = '0'

It would be easy to change the regex to pick the first indexer instead like so:
^(.*?)\[\s*([^\s]*)\s*\]\s*
but I'm not sure if that would break anything and if that's enough to properly support nested indexers. Is this a feature the SimpleDataBinder should support? Since fields that have [] in their name are probably very unlikely to exist, making this change may not be that breaking in real usage.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions