apache / apache/grails-core

Make SimpleDataBinder handle multiple indexers

Open
#15,064 1 comment 0 reactions 0 assignees View on GitHub
relates-to: web layer
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### 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.

Contributor guide

Open the contributing guide

Research direction

Start by locating SimpleDataBinder and its INDEXED_PROPERTY_REGEX definition, then trace how the regex groups become the indexed property name and index. Check the existing binder coverage before deciding how nested indexers should behave; done means multiple indexers are parsed according to the agreed semantics without breaking existing property binding.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.