DATACMNS-1264 - MapDataBinder now rejects improper property expressions.
We now make sure that type expressions cannot be used in SpEL expressions handled by MapDataBinder. They're gonna be rejected by considering the property not writable. SpEL expression evaluation errors are now forwarded as NotWritablePropertyException to make sure the failure gets handled as if the property referred to doesn't exist.
This commit is contained in:
@@ -28,8 +28,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.ConfigurablePropertyAccessor;
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.NotWritablePropertyException;
|
||||
import org.springframework.beans.PropertyValues;
|
||||
import org.springframework.expression.spel.SpelEvaluationException;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat.ISO;
|
||||
import org.springframework.format.support.DefaultFormattingConversionService;
|
||||
@@ -91,7 +94,29 @@ public class MapDataBinderUnitTests {
|
||||
MutablePropertyValues values = new MutablePropertyValues();
|
||||
values.add("somethingWeird", "Value");
|
||||
|
||||
assertThat(bind(values)).isEqualTo(Collections.<String, Object> emptyMap());
|
||||
assertThat(bind(values)).isEqualTo(Collections.emptyMap());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1264
|
||||
public void dropsMapExpressionsForCollectionReferences() {
|
||||
|
||||
ConfigurablePropertyAccessor accessor = new MapDataBinder(Bar.class, new DefaultFormattingConversionService())
|
||||
.getPropertyAccessor();
|
||||
|
||||
assertThatExceptionOfType(NotWritablePropertyException.class) //
|
||||
.isThrownBy(() -> accessor.setPropertyValue("fooBar['foo']", null)) //
|
||||
.withCauseInstanceOf(SpelEvaluationException.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1264
|
||||
public void rejectsExpressionContainingTypeExpression() {
|
||||
|
||||
ConfigurablePropertyAccessor accessor = new MapDataBinder(Bar.class, new DefaultFormattingConversionService())
|
||||
.getPropertyAccessor();
|
||||
|
||||
assertThatExceptionOfType(NotWritablePropertyException.class) //
|
||||
.isThrownBy(() -> accessor.setPropertyValue("fooBar[T(java.lang.String)]", null)) //
|
||||
.withCauseInstanceOf(SpelEvaluationException.class);
|
||||
}
|
||||
|
||||
private static Map<String, Object> bind(PropertyValues values) {
|
||||
|
||||
Reference in New Issue
Block a user