BeanWrapper avoids StringIndexOutOfBoundsException for incompletely quoted keys
Issue: SPR-14293
This commit is contained in:
parent
a1e9459a43
commit
cf0a0cd5d8
|
|
@ -942,7 +942,8 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA
|
|||
actualName = propertyName.substring(0, keyStart);
|
||||
}
|
||||
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);
|
||||
}
|
||||
keys.add(key);
|
||||
|
|
|
|||
|
|
@ -202,6 +202,19 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
|||
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")
|
||||
private interface AliasedProperty {
|
||||
|
|
|
|||
Loading…
Reference in New Issue