Skip to content

Handle nested brackets in a map keys [SPR-1274] #5976

Closed
@spring-projects-issues

Description

@spring-projects-issues

Christian Nelson opened SPR-1274 and commented

If the map key contains nested brackets, the key is not properly extracted from the string by BeanWrapperImpl.getPropertyNameTokens(String propertyName).

For example, consider these 'paths':

  1. "entries[some text[abc]]", key = "some text[abc" (missing ])
  2. "entries['some text[abc]']", key = "'some text[abc" (missing ]')
  3. "entries["some text[abc]"]", key = ""some text[abc" (missing ]")

The first one is kinda a stretch, and I didn't expect it to work. My natural reaction was to try the second and third, thinking that grouping it would do the trick. It didn't though.

This came up in the web application I'm working on. There's a form with let's the user assign IDs to textual names. The name sometimes contain brackets, which triggered this issue.

BeanWrapperImpl.java:610 (1.2.4 source) is the cause. The parser could count braces, and return the key when it's found the first matching pair. In the example above, the first ] would be part of the key, and the second, which completes the initial pair, would complete the key. This solution would work regardless of the single or double quotes. An alternative would be to ignore braces that are in quoted ections of the string. This naturally would only work for scenarios #2 and #3 above.

I will try to update BeanWrapperImpl.java with a sllightly more sophisticated bracket parser and submit a patch with tests. If you think it's a waste of time, or if there's something obvious I'm missing, feel free to point out my error. Regards, Christian


Affects: 1.2.4

Attachments:

Issue Links:

5 votes, 4 watchers

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions