Correctly parse property name in path "map[key[foo]]"

This commit is contained in:
Matthias Kurz
2019-01-11 11:25:27 +01:00
committed by Juergen Hoeller
parent 7b11c3b599
commit 6899624155
3 changed files with 33 additions and 1 deletions

View File

@@ -933,7 +933,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
int keyStart = propertyName.indexOf(PROPERTY_KEY_PREFIX, searchIndex);
searchIndex = -1;
if (keyStart != -1) {
int keyEnd = propertyName.indexOf(PROPERTY_KEY_SUFFIX, keyStart + PROPERTY_KEY_PREFIX.length());
int keyEnd = getPropertyNameKeyEnd(propertyName, keyStart + PROPERTY_KEY_PREFIX.length());
if (keyEnd != -1) {
if (actualName == null) {
actualName = propertyName.substring(0, keyStart);
@@ -958,6 +958,29 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
return tokens;
}
private static int getPropertyNameKeyEnd(String propertyName, int startIndex) {
int unclosedPrefixes = 0;
int length = propertyName.length();
for (int i = startIndex; i < length; i++) {
switch (propertyName.charAt(i)) {
case PropertyAccessor.PROPERTY_KEY_PREFIX_CHAR:
// The property name contains opening prefix(es)
unclosedPrefixes++;
break;
case PropertyAccessor.PROPERTY_KEY_SUFFIX_CHAR:
if (unclosedPrefixes == 0) {
// No unclosed prefix(es) in the property name (left), this is the suffix we are looking for
return i;
} else {
// This suffix does not close the initial prefix, but one that occurred within the property name
unclosedPrefixes--;
}
break;
}
}
return -1;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(getClass().getName());