BeanWrapper avoids StringIndexOutOfBoundsException for incompletely quoted keys
Issue: SPR-14293
This commit is contained in:
@@ -942,7 +942,8 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||||||
actualName = propertyName.substring(0, keyStart);
|
actualName = propertyName.substring(0, keyStart);
|
||||||
}
|
}
|
||||||
String key = propertyName.substring(keyStart + PROPERTY_KEY_PREFIX.length(), keyEnd);
|
String key = propertyName.substring(keyStart + PROPERTY_KEY_PREFIX.length(), keyEnd);
|
||||||
if ((key.startsWith("'") && key.endsWith("'")) || (key.startsWith("\"") && key.endsWith("\""))) {
|
if (key.length() > 1 && (key.startsWith("'") && key.endsWith("'")) ||
|
||||||
|
(key.startsWith("\"") && key.endsWith("\""))) {
|
||||||
key = key.substring(1, key.length() - 1);
|
key = key.substring(1, key.length() - 1);
|
||||||
}
|
}
|
||||||
keys.add(key);
|
keys.add(key);
|
||||||
|
|||||||
@@ -202,6 +202,19 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
|||||||
assertEquals("x", accessor.getPropertyValue("object.name"));
|
assertEquals("x", accessor.getPropertyValue("object.name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void incompletelyQuotedKeyLeadsToPropertyException() {
|
||||||
|
TestBean target = new TestBean();
|
||||||
|
try {
|
||||||
|
BeanWrapper accessor = createAccessor(target);
|
||||||
|
accessor.setPropertyValue("[']", "foobar");
|
||||||
|
fail("Should throw exception on invalid property");
|
||||||
|
}
|
||||||
|
catch (NotWritablePropertyException ex) {
|
||||||
|
assertNull(ex.getPossibleMatches());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private interface AliasedProperty {
|
private interface AliasedProperty {
|
||||||
|
|||||||
Reference in New Issue
Block a user