Fix QueryMapper property path resolution for nested paths containing numeric values.
Prior to this fix a path that contains numeric values used as position parameters would have been stripped in a way that left out the last digit. This could lead to wrong path resolution if the incorrectly constructed property name accidentally matched an existing one. Closes: #4426 Original Pull Request: #4427
This commit is contained in:
committed by
Christoph Strobl
parent
05c38b819f
commit
2de00cdb2f
@@ -1233,6 +1233,18 @@ public class QueryMapper {
|
||||
|
||||
String rawPath = removePlaceholders(POSITIONAL_OPERATOR,
|
||||
removePlaceholders(DOT_POSITIONAL_PATTERN, pathExpression));
|
||||
// fix xx.11.22.33 becomes xx3, it should be xx.33, then path should be null. (test mapNestedLastBigIntegerFieldCorrectly)
|
||||
if (pathExpression.contains(".")) {
|
||||
String lastDotString = pathExpression.substring(pathExpression.lastIndexOf("."));
|
||||
int lastDotLength = lastDotString.length();
|
||||
int newLength = 0;
|
||||
if (rawPath.contains(".")) {
|
||||
newLength = rawPath.substring(rawPath.lastIndexOf(".")).length();
|
||||
}
|
||||
if (lastDotLength != newLength) {
|
||||
rawPath = rawPath.substring(0, rawPath.length() - 1) + lastDotString;
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceProperty != null && sourceProperty.getOwner().equals(entity)) {
|
||||
return mappingContext.getPersistentPropertyPath(
|
||||
|
||||
@@ -1217,6 +1217,16 @@ class UpdateMapperUnitTests {
|
||||
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document("levelOne.0.1.3", "4")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapNestedLastBigIntegerFieldCorrectly() {
|
||||
|
||||
Update update = new Update().set("levelOne.0.1.32", "4");
|
||||
Document mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
|
||||
context.getPersistentEntity(EntityWithNestedMap.class));
|
||||
|
||||
assertThat(mappedUpdate).isEqualTo(new org.bson.Document("$set", new org.bson.Document("levelOne.0.1.32", "4")));
|
||||
}
|
||||
|
||||
@Test // GH-3775
|
||||
void mapNestedMixedStringIntegerFieldCorrectly() {
|
||||
|
||||
@@ -1732,6 +1742,8 @@ class UpdateMapperUnitTests {
|
||||
|
||||
static class EntityWithNestedMap {
|
||||
Map<String, Map<String, Map<String, Object>>> levelOne;
|
||||
// for test mapNestedLastBigIntegerFieldCorrectly()
|
||||
Map<String, Map<String, Map<String, Object>>> levelOne2;
|
||||
}
|
||||
|
||||
static class Customer {
|
||||
|
||||
Reference in New Issue
Block a user